<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE CPP, NoImplicitPrelude, CApiFFI #-}</span><span>
</span><span id="line-3"></span><span>
</span><span id="line-4"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- Module      :  System.IO</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 2001</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-9"></span><span class="hs-comment">--</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Stability   :  stable</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Portability :  portable</span><span>
</span><span id="line-13"></span><span class="hs-comment">--</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- The standard IO library.</span><span>
</span><span id="line-15"></span><span class="hs-comment">--</span><span>
</span><span id="line-16"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-17"></span><span>
</span><span id="line-18"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">System.IO</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-19"></span><span>    </span><span class="annot"><span class="hs-comment">-- * The IO monad</span></span><span>
</span><span id="line-20"></span><span>
</span><span id="line-21"></span><span>    </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier">IO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-22"></span><span>    </span><span class="annot"><a href="System.IO.html#fixIO"><span class="hs-identifier">fixIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-23"></span><span>
</span><span id="line-24"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Files and handles</span></span><span>
</span><span id="line-25"></span><span>
</span><span id="line-26"></span><span>    </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier">FilePath</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-27"></span><span>
</span><span id="line-28"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier">Handle</span></a></span><span class="hs-special">,</span><span>             </span><span class="hs-comment">-- abstract, instance of: Eq, Show.</span><span>
</span><span id="line-29"></span><span>
</span><span id="line-30"></span><span>    </span><span class="hs-comment">-- | GHC note: a 'Handle' will be automatically closed when the garbage</span><span>
</span><span id="line-31"></span><span>    </span><span class="hs-comment">-- collector detects that it has become unreferenced by the program.</span><span>
</span><span id="line-32"></span><span>    </span><span class="hs-comment">-- However, relying on this behaviour is not generally recommended:</span><span>
</span><span id="line-33"></span><span>    </span><span class="hs-comment">-- the garbage collector is unpredictable.  If possible, use</span><span>
</span><span id="line-34"></span><span>    </span><span class="hs-comment">-- an explicit 'hClose' to close 'Handle's when they are no longer</span><span>
</span><span id="line-35"></span><span>    </span><span class="hs-comment">-- required.  GHC does not currently attempt to free up file</span><span>
</span><span id="line-36"></span><span>    </span><span class="hs-comment">-- descriptors when they have run out, it is your responsibility to</span><span>
</span><span id="line-37"></span><span>    </span><span class="hs-comment">-- ensure that this doesn't happen.</span><span>
</span><span id="line-38"></span><span>
</span><span id="line-39"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Standard handles</span></span><span>
</span><span id="line-40"></span><span>
</span><span id="line-41"></span><span>    </span><span class="hs-comment">-- | Three handles are allocated during program initialisation,</span><span>
</span><span id="line-42"></span><span>    </span><span class="hs-comment">-- and are initially open.</span><span>
</span><span id="line-43"></span><span>
</span><span id="line-44"></span><span>    </span><span class="annot"><a href="GHC.IO.StdHandles.html#stdin"><span class="hs-identifier">stdin</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.StdHandles.html#stdout"><span class="hs-identifier">stdout</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.StdHandles.html#stderr"><span class="hs-identifier">stderr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-45"></span><span>
</span><span id="line-46"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Opening and closing files</span></span><span>
</span><span id="line-47"></span><span>
</span><span id="line-48"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Opening files</span></span><span>
</span><span id="line-49"></span><span>
</span><span id="line-50"></span><span>    </span><span class="annot"><a href="System.IO.html#withFile"><span class="hs-identifier">withFile</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-51"></span><span>    </span><span class="annot"><a href="GHC.IO.StdHandles.html#openFile"><span class="hs-identifier">openFile</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-52"></span><span>    </span><span class="annot"><a href="GHC.IO.IOMode.html#IOMode"><span class="hs-identifier">IOMode</span></a></span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.IOMode.html#ReadMode"><span class="hs-identifier">ReadMode</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.IO.IOMode.html#WriteMode"><span class="hs-identifier">WriteMode</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.IO.IOMode.html#AppendMode"><span class="hs-identifier">AppendMode</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.IO.IOMode.html#ReadWriteMode"><span class="hs-identifier">ReadWriteMode</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-53"></span><span>
</span><span id="line-54"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Closing files</span></span><span>
</span><span id="line-55"></span><span>
</span><span id="line-56"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hClose"><span class="hs-identifier">hClose</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-57"></span><span>
</span><span id="line-58"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Special cases</span></span><span>
</span><span id="line-59"></span><span>
</span><span id="line-60"></span><span>    </span><span class="annot"><span class="hs-comment">-- | These functions are also exported by the &quot;Prelude&quot;.</span></span><span>
</span><span id="line-61"></span><span>
</span><span id="line-62"></span><span>    </span><span class="annot"><a href="System.IO.html#readFile"><span class="hs-identifier">readFile</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-63"></span><span>    </span><span class="annot"><a href="System.IO.html#readFile%27"><span class="hs-identifier">readFile'</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-64"></span><span>    </span><span class="annot"><a href="System.IO.html#writeFile"><span class="hs-identifier">writeFile</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-65"></span><span>    </span><span class="annot"><a href="System.IO.html#appendFile"><span class="hs-identifier">appendFile</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-66"></span><span>
</span><span id="line-67"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** File locking</span></span><span>
</span><span id="line-68"></span><span>
</span><span id="line-69"></span><span>    </span><span class="annot"><span class="hs-comment">-- $locking</span></span><span>
</span><span id="line-70"></span><span>
</span><span id="line-71"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Operations on handles</span></span><span>
</span><span id="line-72"></span><span>
</span><span id="line-73"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Determining and changing the size of a file</span></span><span>
</span><span id="line-74"></span><span>
</span><span id="line-75"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hFileSize"><span class="hs-identifier">hFileSize</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-76"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hSetFileSize"><span class="hs-identifier">hSetFileSize</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-77"></span><span>
</span><span id="line-78"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Detecting the end of input</span></span><span>
</span><span id="line-79"></span><span>
</span><span id="line-80"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hIsEOF"><span class="hs-identifier">hIsEOF</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-81"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#isEOF"><span class="hs-identifier">isEOF</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-82"></span><span>
</span><span id="line-83"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Buffering operations</span></span><span>
</span><span id="line-84"></span><span>
</span><span id="line-85"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Types.html#BufferMode"><span class="hs-identifier">BufferMode</span></a></span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#NoBuffering"><span class="hs-identifier">NoBuffering</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.IO.Handle.Types.html#LineBuffering"><span class="hs-identifier">LineBuffering</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.IO.Handle.Types.html#BlockBuffering"><span class="hs-identifier">BlockBuffering</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-86"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hSetBuffering"><span class="hs-identifier">hSetBuffering</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-87"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hGetBuffering"><span class="hs-identifier">hGetBuffering</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-88"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hFlush"><span class="hs-identifier">hFlush</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-89"></span><span>
</span><span id="line-90"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Repositioning handles</span></span><span>
</span><span id="line-91"></span><span>
</span><span id="line-92"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hGetPosn"><span class="hs-identifier">hGetPosn</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-93"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hSetPosn"><span class="hs-identifier">hSetPosn</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-94"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#HandlePosn"><span class="hs-identifier">HandlePosn</span></a></span><span class="hs-special">,</span><span>                </span><span class="hs-comment">-- abstract, instance of: Eq, Show.</span><span>
</span><span id="line-95"></span><span>
</span><span id="line-96"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hSeek"><span class="hs-identifier">hSeek</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-97"></span><span>    </span><span class="annot"><a href="GHC.IO.Device.html#SeekMode"><span class="hs-identifier">SeekMode</span></a></span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Device.html#AbsoluteSeek"><span class="hs-identifier">AbsoluteSeek</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.IO.Device.html#RelativeSeek"><span class="hs-identifier">RelativeSeek</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.IO.Device.html#SeekFromEnd"><span class="hs-identifier">SeekFromEnd</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-98"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hTell"><span class="hs-identifier">hTell</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-99"></span><span>
</span><span id="line-100"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Handle properties</span></span><span>
</span><span id="line-101"></span><span>
</span><span id="line-102"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hIsOpen"><span class="hs-identifier">hIsOpen</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.html#hIsClosed"><span class="hs-identifier">hIsClosed</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-103"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hIsReadable"><span class="hs-identifier">hIsReadable</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.html#hIsWritable"><span class="hs-identifier">hIsWritable</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-104"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hIsSeekable"><span class="hs-identifier">hIsSeekable</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-105"></span><span>
</span><span id="line-106"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Terminal operations (not portable: GHC only)</span></span><span>
</span><span id="line-107"></span><span>
</span><span id="line-108"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hIsTerminalDevice"><span class="hs-identifier">hIsTerminalDevice</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-109"></span><span>
</span><span id="line-110"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hSetEcho"><span class="hs-identifier">hSetEcho</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-111"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hGetEcho"><span class="hs-identifier">hGetEcho</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-112"></span><span>
</span><span id="line-113"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Showing handle state (not portable: GHC only)</span></span><span>
</span><span id="line-114"></span><span>
</span><span id="line-115"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hShow"><span class="hs-identifier">hShow</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-116"></span><span>
</span><span id="line-117"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Text input and output</span></span><span>
</span><span id="line-118"></span><span>
</span><span id="line-119"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Text input</span></span><span>
</span><span id="line-120"></span><span>
</span><span id="line-121"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hWaitForInput"><span class="hs-identifier">hWaitForInput</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-122"></span><span>    </span><span class="annot"><a href="System.IO.html#hReady"><span class="hs-identifier">hReady</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-123"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetChar"><span class="hs-identifier">hGetChar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-124"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetLine"><span class="hs-identifier">hGetLine</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-125"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hLookAhead"><span class="hs-identifier">hLookAhead</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-126"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetContents"><span class="hs-identifier">hGetContents</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-127"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetContents%27"><span class="hs-identifier">hGetContents'</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-128"></span><span>
</span><span id="line-129"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Text output</span></span><span>
</span><span id="line-130"></span><span>
</span><span id="line-131"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutChar"><span class="hs-identifier">hPutChar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-132"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutStr"><span class="hs-identifier">hPutStr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-133"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutStrLn"><span class="hs-identifier">hPutStrLn</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-134"></span><span>    </span><span class="annot"><a href="System.IO.html#hPrint"><span class="hs-identifier">hPrint</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-135"></span><span>
</span><span id="line-136"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Special cases for standard input and output</span></span><span>
</span><span id="line-137"></span><span>
</span><span id="line-138"></span><span>    </span><span class="annot"><span class="hs-comment">-- | These functions are also exported by the &quot;Prelude&quot;.</span></span><span>
</span><span id="line-139"></span><span>
</span><span id="line-140"></span><span>    </span><span class="annot"><a href="System.IO.html#interact"><span class="hs-identifier">interact</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-141"></span><span>    </span><span class="annot"><a href="System.IO.html#putChar"><span class="hs-identifier">putChar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-142"></span><span>    </span><span class="annot"><a href="System.IO.html#putStr"><span class="hs-identifier">putStr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-143"></span><span>    </span><span class="annot"><a href="System.IO.html#putStrLn"><span class="hs-identifier">putStrLn</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-144"></span><span>    </span><span class="annot"><a href="System.IO.html#print"><span class="hs-identifier">print</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-145"></span><span>    </span><span class="annot"><a href="System.IO.html#getChar"><span class="hs-identifier">getChar</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-146"></span><span>    </span><span class="annot"><a href="System.IO.html#getLine"><span class="hs-identifier">getLine</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-147"></span><span>    </span><span class="annot"><a href="System.IO.html#getContents"><span class="hs-identifier">getContents</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-148"></span><span>    </span><span class="annot"><a href="System.IO.html#getContents%27"><span class="hs-identifier">getContents'</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-149"></span><span>    </span><span class="annot"><a href="System.IO.html#readIO"><span class="hs-identifier">readIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-150"></span><span>    </span><span class="annot"><a href="System.IO.html#readLn"><span class="hs-identifier">readLn</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-151"></span><span>
</span><span id="line-152"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Binary input and output</span></span><span>
</span><span id="line-153"></span><span>
</span><span id="line-154"></span><span>    </span><span class="annot"><a href="System.IO.html#withBinaryFile"><span class="hs-identifier">withBinaryFile</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-155"></span><span>    </span><span class="annot"><a href="GHC.IO.StdHandles.html#openBinaryFile"><span class="hs-identifier">openBinaryFile</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-156"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hSetBinaryMode"><span class="hs-identifier">hSetBinaryMode</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-157"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutBuf"><span class="hs-identifier">hPutBuf</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-158"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetBuf"><span class="hs-identifier">hGetBuf</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-159"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetBufSome"><span class="hs-identifier">hGetBufSome</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-160"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutBufNonBlocking"><span class="hs-identifier">hPutBufNonBlocking</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-161"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetBufNonBlocking"><span class="hs-identifier">hGetBufNonBlocking</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-162"></span><span>
</span><span id="line-163"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Temporary files</span></span><span>
</span><span id="line-164"></span><span>
</span><span id="line-165"></span><span>    </span><span class="annot"><a href="System.IO.html#openTempFile"><span class="hs-identifier">openTempFile</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-166"></span><span>    </span><span class="annot"><a href="System.IO.html#openBinaryTempFile"><span class="hs-identifier">openBinaryTempFile</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-167"></span><span>    </span><span class="annot"><a href="System.IO.html#openTempFileWithDefaultPermissions"><span class="hs-identifier">openTempFileWithDefaultPermissions</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-168"></span><span>    </span><span class="annot"><a href="System.IO.html#openBinaryTempFileWithDefaultPermissions"><span class="hs-identifier">openBinaryTempFileWithDefaultPermissions</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-169"></span><span>
</span><span id="line-170"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Unicode encoding\/decoding</span></span><span>
</span><span id="line-171"></span><span>
</span><span id="line-172"></span><span>    </span><span class="hs-comment">-- | A text-mode 'Handle' has an associated 'TextEncoding', which</span><span>
</span><span id="line-173"></span><span>    </span><span class="hs-comment">-- is used to decode bytes into Unicode characters when reading,</span><span>
</span><span id="line-174"></span><span>    </span><span class="hs-comment">-- and encode Unicode characters into bytes when writing.</span><span>
</span><span id="line-175"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-176"></span><span>    </span><span class="hs-comment">-- The default 'TextEncoding' is the same as the default encoding</span><span>
</span><span id="line-177"></span><span>    </span><span class="hs-comment">-- on your system, which is also available as 'localeEncoding'.</span><span>
</span><span id="line-178"></span><span>    </span><span class="hs-comment">-- (GHC note: on Windows, we currently do not support double-byte</span><span>
</span><span id="line-179"></span><span>    </span><span class="hs-comment">-- encodings; if the console\'s code page is unsupported, then</span><span>
</span><span id="line-180"></span><span>    </span><span class="hs-comment">-- 'localeEncoding' will be 'latin1'.)</span><span>
</span><span id="line-181"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-182"></span><span>    </span><span class="hs-comment">-- Encoding and decoding errors are always detected and reported,</span><span>
</span><span id="line-183"></span><span>    </span><span class="hs-comment">-- except during lazy I/O ('hGetContents', 'getContents', and</span><span>
</span><span id="line-184"></span><span>    </span><span class="hs-comment">-- 'readFile'), where a decoding error merely results in</span><span>
</span><span id="line-185"></span><span>    </span><span class="hs-comment">-- termination of the character stream, as with other I/O errors.</span><span>
</span><span id="line-186"></span><span>
</span><span id="line-187"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hSetEncoding"><span class="hs-identifier">hSetEncoding</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-188"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hGetEncoding"><span class="hs-identifier">hGetEncoding</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-189"></span><span>
</span><span id="line-190"></span><span>    </span><span class="annot"><span class="hs-comment">-- ** Unicode encodings</span></span><span>
</span><span id="line-191"></span><span>    </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#TextEncoding"><span class="hs-identifier">TextEncoding</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-192"></span><span>    </span><span class="annot"><a href="GHC.IO.Encoding.html#latin1"><span class="hs-identifier">latin1</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-193"></span><span>    </span><span class="annot"><a href="GHC.IO.Encoding.html#utf8"><span class="hs-identifier">utf8</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.html#utf8_bom"><span class="hs-identifier">utf8_bom</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-194"></span><span>    </span><span class="annot"><a href="GHC.IO.Encoding.html#utf16"><span class="hs-identifier">utf16</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.html#utf16le"><span class="hs-identifier">utf16le</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.html#utf16be"><span class="hs-identifier">utf16be</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-195"></span><span>    </span><span class="annot"><a href="GHC.IO.Encoding.html#utf32"><span class="hs-identifier">utf32</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.html#utf32le"><span class="hs-identifier">utf32le</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.html#utf32be"><span class="hs-identifier">utf32be</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-196"></span><span>    </span><span class="annot"><a href="System.IO.html#localeEncoding"><span class="hs-identifier">localeEncoding</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-197"></span><span>    </span><span class="annot"><a href="GHC.IO.Encoding.html#char8"><span class="hs-identifier">char8</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-198"></span><span>    </span><span class="annot"><a href="GHC.IO.Encoding.html#mkTextEncoding"><span class="hs-identifier">mkTextEncoding</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-199"></span><span>
</span><span id="line-200"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Newline conversion</span></span><span>
</span><span id="line-201"></span><span>
</span><span id="line-202"></span><span>    </span><span class="hs-comment">-- | In Haskell, a newline is always represented by the character</span><span>
</span><span id="line-203"></span><span>    </span><span class="hs-comment">-- @\'\\n\'@.  However, in files and external character streams, a</span><span>
</span><span id="line-204"></span><span>    </span><span class="hs-comment">-- newline may be represented by another character sequence, such</span><span>
</span><span id="line-205"></span><span>    </span><span class="hs-comment">-- as @\'\\r\\n\'@.</span><span>
</span><span id="line-206"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-207"></span><span>    </span><span class="hs-comment">-- A text-mode 'Handle' has an associated 'NewlineMode' that</span><span>
</span><span id="line-208"></span><span>    </span><span class="hs-comment">-- specifies how to translate newline characters.  The</span><span>
</span><span id="line-209"></span><span>    </span><span class="hs-comment">-- 'NewlineMode' specifies the input and output translation</span><span>
</span><span id="line-210"></span><span>    </span><span class="hs-comment">-- separately, so that for instance you can translate @\'\\r\\n\'@</span><span>
</span><span id="line-211"></span><span>    </span><span class="hs-comment">-- to @\'\\n\'@ on input, but leave newlines as @\'\\n\'@ on output.</span><span>
</span><span id="line-212"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-213"></span><span>    </span><span class="hs-comment">-- The default 'NewlineMode' for a 'Handle' is</span><span>
</span><span id="line-214"></span><span>    </span><span class="hs-comment">-- 'nativeNewlineMode', which does no translation on Unix systems,</span><span>
</span><span id="line-215"></span><span>    </span><span class="hs-comment">-- but translates @\'\\r\\n\'@ to @\'\\n\'@ and back on Windows.</span><span>
</span><span id="line-216"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-217"></span><span>    </span><span class="hs-comment">-- Binary-mode 'Handle's do no newline translation at all.</span><span>
</span><span id="line-218"></span><span>    </span><span class="hs-comment">--</span><span>
</span><span id="line-219"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.html#hSetNewlineMode"><span class="hs-identifier">hSetNewlineMode</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-220"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Newline"><span class="hs-identifier">Newline</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#nativeNewline"><span class="hs-identifier">nativeNewline</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-221"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Types.html#NewlineMode"><span class="hs-identifier">NewlineMode</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-222"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Types.html#noNewlineTranslation"><span class="hs-identifier">noNewlineTranslation</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#universalNewlineMode"><span class="hs-identifier">universalNewlineMode</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#nativeNewlineMode"><span class="hs-identifier">nativeNewlineMode</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-223"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-224"></span><span>
</span><span id="line-225"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Control.Exception.Base.html"><span class="hs-identifier">Control.Exception.Base</span></a></span><span>
</span><span id="line-226"></span><span>
</span><span id="line-227"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Bits.html"><span class="hs-identifier">Data.Bits</span></a></span><span>
</span><span id="line-228"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Maybe.html"><span class="hs-identifier">Data.Maybe</span></a></span><span>
</span><span id="line-229"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.C.Error.html"><span class="hs-identifier">Foreign.C.Error</span></a></span><span class="hs-cpp">
#if defined(mingw32_HOST_OS)
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.C.String.html"><span class="hs-identifier">Foreign.C.String</span></a></span><span>
</span><span id="line-232"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Ptr.html"><span class="hs-identifier">Foreign.Ptr</span></a></span><span>
</span><span id="line-233"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Marshal.Alloc.html"><span class="hs-identifier">Foreign.Marshal.Alloc</span></a></span><span>
</span><span id="line-234"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Storable.html"><span class="hs-identifier">Foreign.Storable</span></a></span><span>
</span><span id="line-235"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.SubSystem.html"><span class="hs-identifier">GHC.IO.SubSystem</span></a></span><span>
</span><span id="line-236"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Windows.Handle.html"><span class="hs-identifier">GHC.IO.Windows.Handle</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Windows.Handle.html#openFileAsTemp"><span class="hs-identifier">openFileAsTemp</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-237"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Windows.html"><span class="hs-identifier">GHC.IO.Handle.Windows</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Windows.html#mkHandleFromHANDLE"><span class="hs-identifier">mkHandleFromHANDLE</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-238"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Device.html"><span class="hs-identifier">GHC.IO.Device</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">IODevice</span></span><span>
</span><span id="line-239"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Real.html"><span class="hs-identifier">GHC.Real</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier">fromIntegral</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-240"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Marshal.Utils.html"><span class="hs-identifier">Foreign.Marshal.Utils</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Foreign.Marshal.Utils.html#new"><span class="hs-identifier">new</span></a></span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.C.Types.html"><span class="hs-identifier">Foreign.C.Types</span></a></span><span>
</span><span id="line-243"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="System.Posix.Internals.html"><span class="hs-identifier">System.Posix.Internals</span></a></span><span>
</span><span id="line-244"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="System.Posix.Types.html"><span class="hs-identifier">System.Posix.Types</span></a></span><span>
</span><span id="line-245"></span><span>
</span><span id="line-246"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-247"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.List.html"><span class="hs-identifier">GHC.List</span></a></span><span class="hs-cpp">
#if !defined(mingw32_HOST_OS)
</span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IORef</span><span class="hs-cpp">
#endif
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Num.html"><span class="hs-identifier">GHC.Num</span></a></span><span>
</span><span id="line-252"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.html"><span class="hs-identifier">GHC.IO</span></a></span><span> </span><span class="hs-keyword">hiding</span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.IO.html#bracket"><span class="hs-identifier">bracket</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#onException"><span class="hs-identifier">onException</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-253"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.IOMode.html"><span class="hs-identifier">GHC.IO.IOMode</span></a></span><span>
</span><span id="line-254"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="GHC.IO.FD.html"><span class="hs-identifier">GHC.IO.FD</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">FD</span></span><span>
</span><span id="line-255"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Handle.html"><span class="hs-identifier">GHC.IO.Handle</span></a></span><span>
</span><span id="line-256"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="GHC.IO.Handle.FD.html"><span class="hs-identifier">GHC.IO.Handle.FD</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">POSIX</span></span><span>
</span><span id="line-257"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Text.html"><span class="hs-identifier">GHC.IO.Handle.Text</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetBufSome"><span class="hs-identifier">hGetBufSome</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutStrLn"><span class="hs-identifier">hPutStrLn</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-258"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html"><span class="hs-identifier">GHC.IO.Exception</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html#userError"><span class="hs-identifier">userError</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-259"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.html"><span class="hs-identifier">GHC.IO.Encoding</span></a></span><span>
</span><span id="line-260"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Text.Read.html"><span class="hs-identifier">Text.Read</span></a></span><span>
</span><span id="line-261"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.StdHandles.html"><span class="hs-identifier">GHC.IO.StdHandles</span></a></span><span>
</span><span id="line-262"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Show.html"><span class="hs-identifier">GHC.Show</span></a></span><span>
</span><span id="line-263"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.MVar.html"><span class="hs-identifier">GHC.MVar</span></a></span><span>
</span><span id="line-264"></span><span>
</span><span id="line-265"></span><span class="hs-comment">-- -----------------------------------------------------------------------------</span><span>
</span><span id="line-266"></span><span class="hs-comment">-- Standard IO</span><span>
</span><span id="line-267"></span><span>
</span><span id="line-268"></span><span class="hs-comment">-- | Write a character to the standard output device</span><span>
</span><span id="line-269"></span><span class="hs-comment">-- (same as 'hPutChar' 'stdout').</span><span>
</span><span id="line-270"></span><span>
</span><span id="line-271"></span><span class="annot"><a href="System.IO.html#putChar"><span class="hs-identifier hs-type">putChar</span></a></span><span>         </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-272"></span><span id="putChar"><span class="annot"><span class="annottext">putChar :: Char -&gt; IO ()
</span><a href="System.IO.html#putChar"><span class="hs-identifier hs-var hs-var">putChar</span></a></span></span><span> </span><span id="local-6989586621679519227"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679519227"><span class="hs-identifier hs-var">c</span></a></span></span><span>       </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Handle -&gt; Char -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutChar"><span class="hs-identifier hs-var">hPutChar</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="GHC.IO.StdHandles.html#stdout"><span class="hs-identifier hs-var">stdout</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679519227"><span class="hs-identifier hs-var">c</span></a></span><span>
</span><span id="line-273"></span><span>
</span><span id="line-274"></span><span class="hs-comment">-- | Write a string to the standard output device</span><span>
</span><span id="line-275"></span><span class="hs-comment">-- (same as 'hPutStr' 'stdout').</span><span>
</span><span id="line-276"></span><span>
</span><span id="line-277"></span><span class="annot"><a href="System.IO.html#putStr"><span class="hs-identifier hs-type">putStr</span></a></span><span>          </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-278"></span><span id="putStr"><span class="annot"><span class="annottext">putStr :: String -&gt; IO ()
</span><a href="System.IO.html#putStr"><span class="hs-identifier hs-var hs-var">putStr</span></a></span></span><span> </span><span id="local-6989586621679519226"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519226"><span class="hs-identifier hs-var">s</span></a></span></span><span>        </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutStr"><span class="hs-identifier hs-var">hPutStr</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="GHC.IO.StdHandles.html#stdout"><span class="hs-identifier hs-var">stdout</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519226"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-279"></span><span>
</span><span id="line-280"></span><span class="hs-comment">-- | The same as 'putStr', but adds a newline character.</span><span>
</span><span id="line-281"></span><span>
</span><span id="line-282"></span><span class="annot"><a href="System.IO.html#putStrLn"><span class="hs-identifier hs-type">putStrLn</span></a></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-283"></span><span id="putStrLn"><span class="annot"><span class="annottext">putStrLn :: String -&gt; IO ()
</span><a href="System.IO.html#putStrLn"><span class="hs-identifier hs-var hs-var">putStrLn</span></a></span></span><span> </span><span id="local-6989586621679519225"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519225"><span class="hs-identifier hs-var">s</span></a></span></span><span>      </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutStrLn"><span class="hs-identifier hs-var">hPutStrLn</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="GHC.IO.StdHandles.html#stdout"><span class="hs-identifier hs-var">stdout</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519225"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-284"></span><span>
</span><span id="line-285"></span><span class="hs-comment">-- | The 'print' function outputs a value of any printable type to the</span><span>
</span><span id="line-286"></span><span class="hs-comment">-- standard output device.</span><span>
</span><span id="line-287"></span><span class="hs-comment">-- Printable types are those that are instances of class 'Show'; 'print'</span><span>
</span><span id="line-288"></span><span class="hs-comment">-- converts values to strings for output using the 'show' operation and</span><span>
</span><span id="line-289"></span><span class="hs-comment">-- adds a newline.</span><span>
</span><span id="line-290"></span><span class="hs-comment">--</span><span>
</span><span id="line-291"></span><span class="hs-comment">-- For example, a program to print the first 20 integers and their</span><span>
</span><span id="line-292"></span><span class="hs-comment">-- powers of 2 could be written as:</span><span>
</span><span id="line-293"></span><span class="hs-comment">--</span><span>
</span><span id="line-294"></span><span class="hs-comment">-- &gt; main = print ([(n, 2^n) | n &lt;- [0..19]])</span><span>
</span><span id="line-295"></span><span>
</span><span id="line-296"></span><span id="local-6989586621679519440"><span class="annot"><a href="System.IO.html#print"><span class="hs-identifier hs-type">print</span></a></span><span>           </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Show.html#Show"><span class="hs-identifier hs-type">Show</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679519440"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679519440"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-297"></span><span id="print"><span class="annot"><span class="annottext">print :: forall a. Show a =&gt; a -&gt; IO ()
</span><a href="System.IO.html#print"><span class="hs-identifier hs-var hs-var">print</span></a></span></span><span> </span><span id="local-6989586621679519222"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679519222"><span class="hs-identifier hs-var">x</span></a></span></span><span>         </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="System.IO.html#putStrLn"><span class="hs-identifier hs-var">putStrLn</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679519222"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-298"></span><span>
</span><span id="line-299"></span><span class="hs-comment">-- | Read a character from the standard input device</span><span>
</span><span id="line-300"></span><span class="hs-comment">-- (same as 'hGetChar' 'stdin').</span><span>
</span><span id="line-301"></span><span>
</span><span id="line-302"></span><span class="annot"><a href="System.IO.html#getChar"><span class="hs-identifier hs-type">getChar</span></a></span><span>         </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span>
</span><span id="line-303"></span><span id="getChar"><span class="annot"><span class="annottext">getChar :: IO Char
</span><a href="System.IO.html#getChar"><span class="hs-identifier hs-var hs-var">getChar</span></a></span></span><span>         </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Handle -&gt; IO Char
</span><a href="GHC.IO.Handle.Text.html#hGetChar"><span class="hs-identifier hs-var">hGetChar</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="GHC.IO.StdHandles.html#stdin"><span class="hs-identifier hs-var">stdin</span></a></span><span>
</span><span id="line-304"></span><span>
</span><span id="line-305"></span><span class="hs-comment">-- | Read a line from the standard input device</span><span>
</span><span id="line-306"></span><span class="hs-comment">-- (same as 'hGetLine' 'stdin').</span><span>
</span><span id="line-307"></span><span>
</span><span id="line-308"></span><span class="annot"><a href="System.IO.html#getLine"><span class="hs-identifier hs-type">getLine</span></a></span><span>         </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-309"></span><span id="getLine"><span class="annot"><span class="annottext">getLine :: IO String
</span><a href="System.IO.html#getLine"><span class="hs-identifier hs-var hs-var">getLine</span></a></span></span><span>         </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Handle -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#hGetLine"><span class="hs-identifier hs-var">hGetLine</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="GHC.IO.StdHandles.html#stdin"><span class="hs-identifier hs-var">stdin</span></a></span><span>
</span><span id="line-310"></span><span>
</span><span id="line-311"></span><span class="hs-comment">-- | The 'getContents' operation returns all user input as a single string,</span><span>
</span><span id="line-312"></span><span class="hs-comment">-- which is read lazily as it is needed</span><span>
</span><span id="line-313"></span><span class="hs-comment">-- (same as 'hGetContents' 'stdin').</span><span>
</span><span id="line-314"></span><span>
</span><span id="line-315"></span><span class="annot"><a href="System.IO.html#getContents"><span class="hs-identifier hs-type">getContents</span></a></span><span>     </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-316"></span><span id="getContents"><span class="annot"><span class="annottext">getContents :: IO String
</span><a href="System.IO.html#getContents"><span class="hs-identifier hs-var hs-var">getContents</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Handle -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#hGetContents"><span class="hs-identifier hs-var">hGetContents</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="GHC.IO.StdHandles.html#stdin"><span class="hs-identifier hs-var">stdin</span></a></span><span>
</span><span id="line-317"></span><span>
</span><span id="line-318"></span><span class="hs-comment">-- | The 'getContents'' operation returns all user input as a single string,</span><span>
</span><span id="line-319"></span><span class="hs-comment">-- which is fully read before being returned</span><span>
</span><span id="line-320"></span><span class="hs-comment">-- (same as 'hGetContents'' 'stdin').</span><span>
</span><span id="line-321"></span><span class="hs-comment">--</span><span>
</span><span id="line-322"></span><span class="hs-comment">-- @since 4.15.0.0</span><span>
</span><span id="line-323"></span><span>
</span><span id="line-324"></span><span class="annot"><a href="System.IO.html#getContents%27"><span class="hs-identifier hs-type">getContents'</span></a></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-325"></span><span id="getContents%27"><span class="annot"><span class="annottext">getContents' :: IO String
</span><a href="System.IO.html#getContents%27"><span class="hs-identifier hs-var hs-var">getContents'</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Handle -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#hGetContents%27"><span class="hs-identifier hs-var">hGetContents'</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="GHC.IO.StdHandles.html#stdin"><span class="hs-identifier hs-var">stdin</span></a></span><span>
</span><span id="line-326"></span><span>
</span><span id="line-327"></span><span class="hs-comment">-- | The 'interact' function takes a function of type @String-&gt;String@</span><span>
</span><span id="line-328"></span><span class="hs-comment">-- as its argument.  The entire input from the standard input device is</span><span>
</span><span id="line-329"></span><span class="hs-comment">-- passed to this function as its argument, and the resulting string is</span><span>
</span><span id="line-330"></span><span class="hs-comment">-- output on the standard output device.</span><span>
</span><span id="line-331"></span><span>
</span><span id="line-332"></span><span class="annot"><a href="System.IO.html#interact"><span class="hs-identifier hs-type">interact</span></a></span><span>        </span><span class="hs-glyph">::</span><span>  </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-333"></span><span id="interact"><span class="annot"><span class="annottext">interact :: (String -&gt; String) -&gt; IO ()
</span><a href="System.IO.html#interact"><span class="hs-identifier hs-var hs-var">interact</span></a></span></span><span> </span><span id="local-6989586621679519220"><span class="annot"><span class="annottext">String -&gt; String
</span><a href="#local-6989586621679519220"><span class="hs-identifier hs-var">f</span></a></span></span><span>      </span><span class="hs-glyph">=</span><span>   </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679519219"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519219"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO String
</span><a href="System.IO.html#getContents"><span class="hs-identifier hs-var">getContents</span></a></span><span>
</span><span id="line-334"></span><span>                       </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="System.IO.html#putStr"><span class="hs-identifier hs-var">putStr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; String
</span><a href="#local-6989586621679519220"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519219"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-335"></span><span>
</span><span id="line-336"></span><span class="hs-comment">-- | The 'readFile' function reads a file and</span><span>
</span><span id="line-337"></span><span class="hs-comment">-- returns the contents of the file as a string.</span><span>
</span><span id="line-338"></span><span class="hs-comment">-- The file is read lazily, on demand, as with 'getContents'.</span><span>
</span><span id="line-339"></span><span>
</span><span id="line-340"></span><span class="annot"><a href="System.IO.html#readFile"><span class="hs-identifier hs-type">readFile</span></a></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-341"></span><span id="readFile"><span class="annot"><span class="annottext">readFile :: String -&gt; IO String
</span><a href="System.IO.html#readFile"><span class="hs-identifier hs-var hs-var">readFile</span></a></span></span><span> </span><span id="local-6989586621679519218"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519218"><span class="hs-identifier hs-var">name</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">String -&gt; IOMode -&gt; IO Handle
</span><a href="GHC.IO.StdHandles.html#openFile"><span class="hs-identifier hs-var">openFile</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519218"><span class="hs-identifier hs-var">name</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="GHC.IO.IOMode.html#ReadMode"><span class="hs-identifier hs-var">ReadMode</span></a></span><span> </span><span class="annot"><span class="annottext">IO Handle -&gt; (Handle -&gt; IO String) -&gt; IO String
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Handle -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#hGetContents"><span class="hs-identifier hs-var">hGetContents</span></a></span><span>
</span><span id="line-342"></span><span>
</span><span id="line-343"></span><span class="hs-comment">-- | The 'readFile'' function reads a file and</span><span>
</span><span id="line-344"></span><span class="hs-comment">-- returns the contents of the file as a string.</span><span>
</span><span id="line-345"></span><span class="hs-comment">-- The file is fully read before being returned, as with 'getContents''.</span><span>
</span><span id="line-346"></span><span class="hs-comment">--</span><span>
</span><span id="line-347"></span><span class="hs-comment">-- @since 4.15.0.0</span><span>
</span><span id="line-348"></span><span>
</span><span id="line-349"></span><span class="annot"><a href="System.IO.html#readFile%27"><span class="hs-identifier hs-type">readFile'</span></a></span><span>       </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-350"></span><span id="readFile%27"><span class="annot"><span class="annottext">readFile' :: String -&gt; IO String
</span><a href="System.IO.html#readFile%27"><span class="hs-identifier hs-var hs-var">readFile'</span></a></span></span><span> </span><span id="local-6989586621679519217"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519217"><span class="hs-identifier hs-var">name</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">String -&gt; IOMode -&gt; IO Handle
</span><a href="GHC.IO.StdHandles.html#openFile"><span class="hs-identifier hs-var">openFile</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519217"><span class="hs-identifier hs-var">name</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="GHC.IO.IOMode.html#ReadMode"><span class="hs-identifier hs-var">ReadMode</span></a></span><span> </span><span class="annot"><span class="annottext">IO Handle -&gt; (Handle -&gt; IO String) -&gt; IO String
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Handle -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#hGetContents%27"><span class="hs-identifier hs-var">hGetContents'</span></a></span><span>
</span><span id="line-351"></span><span>
</span><span id="line-352"></span><span class="hs-comment">-- | The computation 'writeFile' @file str@ function writes the string @str@,</span><span>
</span><span id="line-353"></span><span class="hs-comment">-- to the file @file@.</span><span>
</span><span id="line-354"></span><span class="annot"><a href="System.IO.html#writeFile"><span class="hs-identifier hs-type">writeFile</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-355"></span><span id="writeFile"><span class="annot"><span class="annottext">writeFile :: String -&gt; String -&gt; IO ()
</span><a href="System.IO.html#writeFile"><span class="hs-identifier hs-var hs-var">writeFile</span></a></span></span><span> </span><span id="local-6989586621679519216"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519216"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621679519215"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519215"><span class="hs-identifier hs-var">txt</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IOMode -&gt; (Handle -&gt; IO ()) -&gt; IO ()
forall r. String -&gt; IOMode -&gt; (Handle -&gt; IO r) -&gt; IO r
</span><a href="System.IO.html#withFile"><span class="hs-identifier hs-var">withFile</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519216"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="GHC.IO.IOMode.html#WriteMode"><span class="hs-identifier hs-var">WriteMode</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679519214"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679519214"><span class="hs-identifier hs-var">hdl</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutStr"><span class="hs-identifier hs-var">hPutStr</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679519214"><span class="hs-identifier hs-var">hdl</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519215"><span class="hs-identifier hs-var">txt</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-356"></span><span>
</span><span id="line-357"></span><span class="hs-comment">-- | The computation 'appendFile' @file str@ function appends the string @str@,</span><span>
</span><span id="line-358"></span><span class="hs-comment">-- to the file @file@.</span><span>
</span><span id="line-359"></span><span class="hs-comment">--</span><span>
</span><span id="line-360"></span><span class="hs-comment">-- Note that 'writeFile' and 'appendFile' write a literal string</span><span>
</span><span id="line-361"></span><span class="hs-comment">-- to a file.  To write a value of any printable type, as with 'print',</span><span>
</span><span id="line-362"></span><span class="hs-comment">-- use the 'show' function to convert the value to a string first.</span><span>
</span><span id="line-363"></span><span class="hs-comment">--</span><span>
</span><span id="line-364"></span><span class="hs-comment">-- &gt; main = appendFile &quot;squares&quot; (show [(x,x*x) | x &lt;- [0,0.1..2]])</span><span>
</span><span id="line-365"></span><span>
</span><span id="line-366"></span><span class="annot"><a href="System.IO.html#appendFile"><span class="hs-identifier hs-type">appendFile</span></a></span><span>      </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-367"></span><span id="appendFile"><span class="annot"><span class="annottext">appendFile :: String -&gt; String -&gt; IO ()
</span><a href="System.IO.html#appendFile"><span class="hs-identifier hs-var hs-var">appendFile</span></a></span></span><span> </span><span id="local-6989586621679519213"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519213"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621679519212"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519212"><span class="hs-identifier hs-var">txt</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IOMode -&gt; (Handle -&gt; IO ()) -&gt; IO ()
forall r. String -&gt; IOMode -&gt; (Handle -&gt; IO r) -&gt; IO r
</span><a href="System.IO.html#withFile"><span class="hs-identifier hs-var">withFile</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519213"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="GHC.IO.IOMode.html#AppendMode"><span class="hs-identifier hs-var">AppendMode</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679519211"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679519211"><span class="hs-identifier hs-var">hdl</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutStr"><span class="hs-identifier hs-var">hPutStr</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679519211"><span class="hs-identifier hs-var">hdl</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519212"><span class="hs-identifier hs-var">txt</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-368"></span><span>
</span><span id="line-369"></span><span class="hs-comment">-- | The 'readLn' function combines 'getLine' and 'readIO'.</span><span>
</span><span id="line-370"></span><span>
</span><span id="line-371"></span><span id="local-6989586621679519432"><span class="annot"><a href="System.IO.html#readLn"><span class="hs-identifier hs-type">readLn</span></a></span><span>          </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Read.html#Read"><span class="hs-identifier hs-type">Read</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679519432"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679519432"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-372"></span><span id="readLn"><span class="annot"><span class="annottext">readLn :: forall a. Read a =&gt; IO a
</span><a href="System.IO.html#readLn"><span class="hs-identifier hs-var hs-var">readLn</span></a></span></span><span>          </span><span class="hs-glyph">=</span><span>  </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679519205"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519205"><span class="hs-identifier hs-var">l</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO String
</span><a href="System.IO.html#getLine"><span class="hs-identifier hs-var">getLine</span></a></span><span>
</span><span id="line-373"></span><span>                      </span><span id="local-6989586621679519204"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679519204"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO a
forall a. Read a =&gt; String -&gt; IO a
</span><a href="System.IO.html#readIO"><span class="hs-identifier hs-var">readIO</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519205"><span class="hs-identifier hs-var">l</span></a></span><span>
</span><span id="line-374"></span><span>                      </span><span class="annot"><span class="annottext">a -&gt; IO a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679519204"><span class="hs-identifier hs-var">r</span></a></span><span>
</span><span id="line-375"></span><span>
</span><span id="line-376"></span><span class="hs-comment">-- | The 'readIO' function is similar to 'read' except that it signals</span><span>
</span><span id="line-377"></span><span class="hs-comment">-- parse failure to the 'IO' monad instead of terminating the program.</span><span>
</span><span id="line-378"></span><span>
</span><span id="line-379"></span><span id="local-6989586621679519430"><span class="annot"><a href="System.IO.html#readIO"><span class="hs-identifier hs-type">readIO</span></a></span><span>          </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Read.html#Read"><span class="hs-identifier hs-type">Read</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679519430"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679519430"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-380"></span><span id="readIO"><span class="annot"><span class="annottext">readIO :: forall a. Read a =&gt; String -&gt; IO a
</span><a href="System.IO.html#readIO"><span class="hs-identifier hs-var hs-var">readIO</span></a></span></span><span> </span><span id="local-6989586621679519194"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519194"><span class="hs-identifier hs-var">s</span></a></span></span><span>        </span><span class="hs-glyph">=</span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="hs-special">(</span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679519193"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679519193"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679519192"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519192"><span class="hs-identifier hs-var">t</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ReadS a
forall a. Read a =&gt; ReadS a
</span><a href="Text.Read.html#reads"><span class="hs-identifier hs-var">reads</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519194"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-special">;</span><span>
</span><span id="line-381"></span><span>                              </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ReadS String
</span><a href="GHC.Read.html#lex"><span class="hs-identifier hs-var">lex</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519192"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="hs-special">;</span><span>
</span><span id="line-382"></span><span>                              </span><span class="annot"><span class="annottext">a -&gt; [a]
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679519193"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-383"></span><span>                        </span><span class="hs-special">[</span><span id="local-6989586621679519189"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679519189"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">]</span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a -&gt; IO a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679519189"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-384"></span><span>                        </span><span class="hs-special">[</span><span class="hs-special">]</span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IOError -&gt; IO a
forall a. IOError -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioError"><span class="hs-identifier hs-var">ioError</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; IOError
</span><a href="GHC.IO.Exception.html#userError"><span class="hs-identifier hs-var">userError</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Prelude.readIO: no parse&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-385"></span><span>                        </span><span class="annot"><span class="annottext">[a]
</span><span class="hs-identifier">_</span></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IOError -&gt; IO a
forall a. IOError -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioError"><span class="hs-identifier hs-var">ioError</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; IOError
</span><a href="GHC.IO.Exception.html#userError"><span class="hs-identifier hs-var">userError</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Prelude.readIO: ambiguous parse&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-386"></span><span>
</span><span id="line-387"></span><span class="hs-comment">-- | The Unicode encoding of the current locale</span><span>
</span><span id="line-388"></span><span class="hs-comment">--</span><span>
</span><span id="line-389"></span><span class="hs-comment">-- This is the initial locale encoding: if it has been subsequently changed by</span><span>
</span><span id="line-390"></span><span class="hs-comment">-- 'GHC.IO.Encoding.setLocaleEncoding' this value will not reflect that change.</span><span>
</span><span id="line-391"></span><span class="annot"><a href="System.IO.html#localeEncoding"><span class="hs-identifier hs-type">localeEncoding</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#TextEncoding"><span class="hs-identifier hs-type">TextEncoding</span></a></span><span>
</span><span id="line-392"></span><span id="localeEncoding"><span class="annot"><span class="annottext">localeEncoding :: TextEncoding
</span><a href="System.IO.html#localeEncoding"><span class="hs-identifier hs-var hs-var">localeEncoding</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TextEncoding
</span><a href="GHC.IO.Encoding.html#initLocaleEncoding"><span class="hs-identifier hs-var">initLocaleEncoding</span></a></span><span>
</span><span id="line-393"></span><span>
</span><span id="line-394"></span><span class="hs-comment">-- | Computation 'hReady' @hdl@ indicates whether at least one item is</span><span>
</span><span id="line-395"></span><span class="hs-comment">-- available for input from handle @hdl@.</span><span>
</span><span id="line-396"></span><span class="hs-comment">--</span><span>
</span><span id="line-397"></span><span class="hs-comment">-- This operation may fail with:</span><span>
</span><span id="line-398"></span><span class="hs-comment">--</span><span>
</span><span id="line-399"></span><span class="hs-comment">--  * 'System.IO.Error.isEOFError' if the end of file has been reached.</span><span>
</span><span id="line-400"></span><span>
</span><span id="line-401"></span><span class="annot"><a href="System.IO.html#hReady"><span class="hs-identifier hs-type">hReady</span></a></span><span>          </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>
</span><span id="line-402"></span><span id="hReady"><span class="annot"><span class="annottext">hReady :: Handle -&gt; IO Bool
</span><a href="System.IO.html#hReady"><span class="hs-identifier hs-var hs-var">hReady</span></a></span></span><span> </span><span id="local-6989586621679519186"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679519186"><span class="hs-identifier hs-var">h</span></a></span></span><span>        </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Handle -&gt; Int -&gt; IO Bool
</span><a href="GHC.IO.Handle.Text.html#hWaitForInput"><span class="hs-identifier hs-var">hWaitForInput</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679519186"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-403"></span><span>
</span><span id="line-404"></span><span class="hs-comment">-- | Computation 'hPrint' @hdl t@ writes the string representation of @t@</span><span>
</span><span id="line-405"></span><span class="hs-comment">-- given by the 'shows' function to the file or channel managed by @hdl@</span><span>
</span><span id="line-406"></span><span class="hs-comment">-- and appends a newline.</span><span>
</span><span id="line-407"></span><span class="hs-comment">--</span><span>
</span><span id="line-408"></span><span class="hs-comment">-- This operation may fail with:</span><span>
</span><span id="line-409"></span><span class="hs-comment">--</span><span>
</span><span id="line-410"></span><span class="hs-comment">--  * 'System.IO.Error.isFullError' if the device is full; or</span><span>
</span><span id="line-411"></span><span class="hs-comment">--</span><span>
</span><span id="line-412"></span><span class="hs-comment">--  * 'System.IO.Error.isPermissionError' if another system resource limit</span><span>
</span><span id="line-413"></span><span class="hs-comment">--    would be exceeded.</span><span>
</span><span id="line-414"></span><span>
</span><span id="line-415"></span><span id="local-6989586621679519422"><span class="annot"><a href="System.IO.html#hPrint"><span class="hs-identifier hs-type">hPrint</span></a></span><span>          </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Show.html#Show"><span class="hs-identifier hs-type">Show</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679519422"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679519422"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-416"></span><span id="hPrint"><span class="annot"><span class="annottext">hPrint :: forall a. Show a =&gt; Handle -&gt; a -&gt; IO ()
</span><a href="System.IO.html#hPrint"><span class="hs-identifier hs-var hs-var">hPrint</span></a></span></span><span> </span><span id="local-6989586621679519183"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679519183"><span class="hs-identifier hs-var">hdl</span></a></span></span><span>      </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutStrLn"><span class="hs-identifier hs-var">hPutStrLn</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679519183"><span class="hs-identifier hs-var">hdl</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; (a -&gt; String) -&gt; a -&gt; IO ()
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span>
</span><span id="line-417"></span><span>
</span><span id="line-418"></span><span class="hs-comment">-- | @'withFile' name mode act@ opens a file using 'openFile' and passes</span><span>
</span><span id="line-419"></span><span class="hs-comment">-- the resulting handle to the computation @act@.  The handle will be</span><span>
</span><span id="line-420"></span><span class="hs-comment">-- closed on exit from 'withFile', whether by normal termination or by</span><span>
</span><span id="line-421"></span><span class="hs-comment">-- raising an exception.  If closing the handle raises an exception, then</span><span>
</span><span id="line-422"></span><span class="hs-comment">-- this exception will be raised by 'withFile' rather than any exception</span><span>
</span><span id="line-423"></span><span class="hs-comment">-- raised by @act@.</span><span>
</span><span id="line-424"></span><span id="local-6989586621679519433"><span class="annot"><a href="System.IO.html#withFile"><span class="hs-identifier hs-type">withFile</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.IOMode.html#IOMode"><span class="hs-identifier hs-type">IOMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679519433"><span class="hs-identifier hs-type">r</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679519433"><span class="hs-identifier hs-type">r</span></a></span></span><span>
</span><span id="line-425"></span><span id="withFile"><span class="annot"><span class="annottext">withFile :: forall r. String -&gt; IOMode -&gt; (Handle -&gt; IO r) -&gt; IO r
</span><a href="System.IO.html#withFile"><span class="hs-identifier hs-var hs-var">withFile</span></a></span></span><span> </span><span id="local-6989586621679519181"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519181"><span class="hs-identifier hs-var">name</span></a></span></span><span> </span><span id="local-6989586621679519180"><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679519180"><span class="hs-identifier hs-var">mode</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO Handle -&gt; (Handle -&gt; IO ()) -&gt; (Handle -&gt; IO r) -&gt; IO r
forall a b c. IO a -&gt; (a -&gt; IO b) -&gt; (a -&gt; IO c) -&gt; IO c
</span><a href="Control.Exception.Base.html#bracket"><span class="hs-identifier hs-var">bracket</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; IOMode -&gt; IO Handle
</span><a href="GHC.IO.StdHandles.html#openFile"><span class="hs-identifier hs-var">openFile</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519181"><span class="hs-identifier hs-var">name</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679519180"><span class="hs-identifier hs-var">mode</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; IO ()
</span><a href="GHC.IO.Handle.html#hClose"><span class="hs-identifier hs-var">hClose</span></a></span><span>
</span><span id="line-426"></span><span>
</span><span id="line-427"></span><span class="hs-comment">-- | @'withBinaryFile' name mode act@ opens a file using 'openBinaryFile'</span><span>
</span><span id="line-428"></span><span class="hs-comment">-- and passes the resulting handle to the computation @act@.  The handle</span><span>
</span><span id="line-429"></span><span class="hs-comment">-- will be closed on exit from 'withBinaryFile', whether by normal</span><span>
</span><span id="line-430"></span><span class="hs-comment">-- termination or by raising an exception.</span><span>
</span><span id="line-431"></span><span id="local-6989586621679519178"><span class="annot"><a href="System.IO.html#withBinaryFile"><span class="hs-identifier hs-type">withBinaryFile</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.IOMode.html#IOMode"><span class="hs-identifier hs-type">IOMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679519178"><span class="hs-identifier hs-type">r</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679519178"><span class="hs-identifier hs-type">r</span></a></span></span><span>
</span><span id="line-432"></span><span id="withBinaryFile"><span class="annot"><span class="annottext">withBinaryFile :: forall r. String -&gt; IOMode -&gt; (Handle -&gt; IO r) -&gt; IO r
</span><a href="System.IO.html#withBinaryFile"><span class="hs-identifier hs-var hs-var">withBinaryFile</span></a></span></span><span> </span><span id="local-6989586621679519177"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519177"><span class="hs-identifier hs-var">name</span></a></span></span><span> </span><span id="local-6989586621679519176"><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679519176"><span class="hs-identifier hs-var">mode</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO Handle -&gt; (Handle -&gt; IO ()) -&gt; (Handle -&gt; IO r) -&gt; IO r
forall a b c. IO a -&gt; (a -&gt; IO b) -&gt; (a -&gt; IO c) -&gt; IO c
</span><a href="Control.Exception.Base.html#bracket"><span class="hs-identifier hs-var">bracket</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; IOMode -&gt; IO Handle
</span><a href="GHC.IO.StdHandles.html#openBinaryFile"><span class="hs-identifier hs-var">openBinaryFile</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519177"><span class="hs-identifier hs-var">name</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679519176"><span class="hs-identifier hs-var">mode</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; IO ()
</span><a href="GHC.IO.Handle.html#hClose"><span class="hs-identifier hs-var">hClose</span></a></span><span>
</span><span id="line-433"></span><span>
</span><span id="line-434"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-435"></span><span class="hs-comment">-- fixIO</span><span>
</span><span id="line-436"></span><span>
</span><span id="line-437"></span><span class="hs-comment">-- | The implementation of 'Control.Monad.Fix.mfix' for 'IO'. If the function</span><span>
</span><span id="line-438"></span><span class="hs-comment">-- passed to 'fixIO' inspects its argument, the resulting action will throw</span><span>
</span><span id="line-439"></span><span class="hs-comment">-- 'FixIOException'.</span><span>
</span><span id="line-440"></span><span id="local-6989586621679519412"><span class="annot"><a href="System.IO.html#fixIO"><span class="hs-identifier hs-type">fixIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679519412"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679519412"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679519412"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-441"></span><span id="fixIO"><span class="annot"><span class="annottext">fixIO :: forall a. (a -&gt; IO a) -&gt; IO a
</span><a href="System.IO.html#fixIO"><span class="hs-identifier hs-var hs-var">fixIO</span></a></span></span><span> </span><span id="local-6989586621679519166"><span class="annot"><span class="annottext">a -&gt; IO a
</span><a href="#local-6989586621679519166"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-442"></span><span>    </span><span id="local-6989586621679519165"><span class="annot"><span class="annottext">MVar a
</span><a href="#local-6989586621679519165"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO (MVar a)
forall a. IO (MVar a)
</span><a href="GHC.MVar.html#newEmptyMVar"><span class="hs-identifier hs-var">newEmptyMVar</span></a></span><span>
</span><span id="line-443"></span><span>    </span><span id="local-6989586621679519163"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679519163"><span class="hs-identifier hs-var">ans</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO a -&gt; IO a
forall a. IO a -&gt; IO a
</span><a href="GHC.IO.Unsafe.html#unsafeDupableInterleaveIO"><span class="hs-identifier hs-var">unsafeDupableInterleaveIO</span></a></span><span>
</span><span id="line-444"></span><span>             </span><span class="hs-special">(</span><span class="annot"><span class="annottext">MVar a -&gt; IO a
forall a. MVar a -&gt; IO a
</span><a href="GHC.MVar.html#readMVar"><span class="hs-identifier hs-var">readMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar a
</span><a href="#local-6989586621679519165"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">IO a -&gt; (BlockedIndefinitelyOnMVar -&gt; IO a) -&gt; IO a
forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catch"><span class="hs-operator hs-var">`catch`</span></a></span><span> </span><span class="hs-glyph">\</span><span class="annot"><span class="annottext">BlockedIndefinitelyOnMVar
</span><a href="GHC.IO.Exception.html#BlockedIndefinitelyOnMVar"><span class="hs-identifier hs-var">BlockedIndefinitelyOnMVar</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-445"></span><span>                                    </span><span class="annot"><span class="annottext">FixIOException -&gt; IO a
forall e a. Exception e =&gt; e -&gt; IO a
</span><a href="GHC.IO.html#throwIO"><span class="hs-identifier hs-var">throwIO</span></a></span><span> </span><span class="annot"><span class="annottext">FixIOException
</span><a href="GHC.IO.Exception.html#FixIOException"><span class="hs-identifier hs-var">FixIOException</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-446"></span><span>    </span><span id="local-6989586621679519156"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679519156"><span class="hs-identifier hs-var">result</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">a -&gt; IO a
</span><a href="#local-6989586621679519166"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679519163"><span class="hs-identifier hs-var">ans</span></a></span><span>
</span><span id="line-447"></span><span>    </span><span class="annot"><span class="annottext">MVar a -&gt; a -&gt; IO ()
forall a. MVar a -&gt; a -&gt; IO ()
</span><a href="GHC.MVar.html#putMVar"><span class="hs-identifier hs-var">putMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar a
</span><a href="#local-6989586621679519165"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679519156"><span class="hs-identifier hs-var">result</span></a></span><span>
</span><span id="line-448"></span><span>    </span><span class="annot"><span class="annottext">a -&gt; IO a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679519156"><span class="hs-identifier hs-var">result</span></a></span><span>
</span><span id="line-449"></span><span>
</span><span id="line-450"></span><span class="hs-comment">-- Note [Blackholing in fixIO]</span><span>
</span><span id="line-451"></span><span class="hs-comment">-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~</span><span>
</span><span id="line-452"></span><span class="hs-comment">--</span><span>
</span><span id="line-453"></span><span class="hs-comment">-- We do our own explicit black holing here, because GHC's lazy</span><span>
</span><span id="line-454"></span><span class="hs-comment">-- blackholing isn't enough.  In an infinite loop, GHC may run the IO</span><span>
</span><span id="line-455"></span><span class="hs-comment">-- computation a few times before it notices the loop, which is wrong.</span><span>
</span><span id="line-456"></span><span class="hs-comment">--</span><span>
</span><span id="line-457"></span><span class="hs-comment">-- NOTE2: the explicit black-holing with an IORef ran into trouble</span><span>
</span><span id="line-458"></span><span class="hs-comment">-- with multiple threads (see #5421), so now we use an MVar. We used</span><span>
</span><span id="line-459"></span><span class="hs-comment">-- to use takeMVar with unsafeInterleaveIO. This, however, uses noDuplicate#,</span><span>
</span><span id="line-460"></span><span class="hs-comment">-- which is not particularly cheap. Better to use readMVar, which can be</span><span>
</span><span id="line-461"></span><span class="hs-comment">-- performed in multiple threads safely, and to use unsafeDupableInterleaveIO</span><span>
</span><span id="line-462"></span><span class="hs-comment">-- to avoid the noDuplicate cost.</span><span>
</span><span id="line-463"></span><span class="hs-comment">--</span><span>
</span><span id="line-464"></span><span class="hs-comment">-- What we'd ideally want is probably an IVar, but we don't quite have those.</span><span>
</span><span id="line-465"></span><span class="hs-comment">-- STM TVars look like an option at first, but I don't think they are:</span><span>
</span><span id="line-466"></span><span class="hs-comment">-- we'd need to be able to write to the variable in an IO context, which can</span><span>
</span><span id="line-467"></span><span class="hs-comment">-- only be done using 'atomically', and 'atomically' is not allowed within</span><span>
</span><span id="line-468"></span><span class="hs-comment">-- unsafePerformIO. We can't know if someone will try to use the result</span><span>
</span><span id="line-469"></span><span class="hs-comment">-- of fixIO with unsafePerformIO!</span><span>
</span><span id="line-470"></span><span class="hs-comment">--</span><span>
</span><span id="line-471"></span><span class="hs-comment">-- See also System.IO.Unsafe.unsafeFixIO.</span><span>
</span><span id="line-472"></span><span class="hs-comment">--</span><span>
</span><span id="line-473"></span><span>
</span><span id="line-474"></span><span class="hs-comment">-- | The function creates a temporary file in ReadWrite mode.</span><span>
</span><span id="line-475"></span><span class="hs-comment">-- The created file isn\'t deleted automatically, so you need to delete it manually.</span><span>
</span><span id="line-476"></span><span class="hs-comment">--</span><span>
</span><span id="line-477"></span><span class="hs-comment">-- The file is created with permissions such that only the current</span><span>
</span><span id="line-478"></span><span class="hs-comment">-- user can read\/write it.</span><span>
</span><span id="line-479"></span><span class="hs-comment">--</span><span>
</span><span id="line-480"></span><span class="hs-comment">-- With some exceptions (see below), the file will be created securely</span><span>
</span><span id="line-481"></span><span class="hs-comment">-- in the sense that an attacker should not be able to cause</span><span>
</span><span id="line-482"></span><span class="hs-comment">-- openTempFile to overwrite another file on the filesystem using your</span><span>
</span><span id="line-483"></span><span class="hs-comment">-- credentials, by putting symbolic links (on Unix) in the place where</span><span>
</span><span id="line-484"></span><span class="hs-comment">-- the temporary file is to be created.  On Unix the @O_CREAT@ and</span><span>
</span><span id="line-485"></span><span class="hs-comment">-- @O_EXCL@ flags are used to prevent this attack, but note that</span><span>
</span><span id="line-486"></span><span class="hs-comment">-- @O_EXCL@ is sometimes not supported on NFS filesystems, so if you</span><span>
</span><span id="line-487"></span><span class="hs-comment">-- rely on this behaviour it is best to use local filesystems only.</span><span>
</span><span id="line-488"></span><span class="hs-comment">--</span><span>
</span><span id="line-489"></span><span class="annot"><a href="System.IO.html#openTempFile"><span class="hs-identifier hs-type">openTempFile</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span>   </span><span class="hs-comment">-- ^ Directory in which to create the file</span><span>
</span><span id="line-490"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>     </span><span class="hs-comment">-- ^ File name template. If the template is \&quot;foo.ext\&quot; then</span><span>
</span><span id="line-491"></span><span>                           </span><span class="hs-comment">-- the created file will be \&quot;fooXXX.ext\&quot; where XXX is some</span><span>
</span><span id="line-492"></span><span>                           </span><span class="hs-comment">-- random number. Note that this should not contain any path</span><span>
</span><span id="line-493"></span><span>                           </span><span class="hs-comment">-- separator characters.</span><span>
</span><span id="line-494"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-495"></span><span id="openTempFile"><span class="annot"><span class="annottext">openTempFile :: String -&gt; String -&gt; IO (String, Handle)
</span><a href="System.IO.html#openTempFile"><span class="hs-identifier hs-var hs-var">openTempFile</span></a></span></span><span> </span><span id="local-6989586621679519154"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519154"><span class="hs-identifier hs-var">tmp_dir</span></a></span></span><span> </span><span id="local-6989586621679519153"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519153"><span class="hs-identifier hs-var">template</span></a></span></span><span>
</span><span id="line-496"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String -&gt; Bool -&gt; CMode -&gt; IO (String, Handle)
</span><a href="System.IO.html#openTempFile%27"><span class="hs-identifier hs-var">openTempFile'</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;openTempFile&quot;</span></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519154"><span class="hs-identifier hs-var">tmp_dir</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519153"><span class="hs-identifier hs-var">template</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span> </span><span class="annot"><span class="annottext">CMode
</span><span class="hs-number">0o600</span></span><span>
</span><span id="line-497"></span><span>
</span><span id="line-498"></span><span class="hs-comment">-- | Like 'openTempFile', but opens the file in binary mode. See 'openBinaryFile' for more comments.</span><span>
</span><span id="line-499"></span><span class="annot"><a href="System.IO.html#openBinaryTempFile"><span class="hs-identifier hs-type">openBinaryTempFile</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-500"></span><span id="openBinaryTempFile"><span class="annot"><span class="annottext">openBinaryTempFile :: String -&gt; String -&gt; IO (String, Handle)
</span><a href="System.IO.html#openBinaryTempFile"><span class="hs-identifier hs-var hs-var">openBinaryTempFile</span></a></span></span><span> </span><span id="local-6989586621679519151"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519151"><span class="hs-identifier hs-var">tmp_dir</span></a></span></span><span> </span><span id="local-6989586621679519150"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519150"><span class="hs-identifier hs-var">template</span></a></span></span><span>
</span><span id="line-501"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String -&gt; Bool -&gt; CMode -&gt; IO (String, Handle)
</span><a href="System.IO.html#openTempFile%27"><span class="hs-identifier hs-var">openTempFile'</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;openBinaryTempFile&quot;</span></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519151"><span class="hs-identifier hs-var">tmp_dir</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519150"><span class="hs-identifier hs-var">template</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span> </span><span class="annot"><span class="annottext">CMode
</span><span class="hs-number">0o600</span></span><span>
</span><span id="line-502"></span><span>
</span><span id="line-503"></span><span class="hs-comment">-- | Like 'openTempFile', but uses the default file permissions</span><span>
</span><span id="line-504"></span><span class="annot"><a href="System.IO.html#openTempFileWithDefaultPermissions"><span class="hs-identifier hs-type">openTempFileWithDefaultPermissions</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-505"></span><span>                                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-506"></span><span id="openTempFileWithDefaultPermissions"><span class="annot"><span class="annottext">openTempFileWithDefaultPermissions :: String -&gt; String -&gt; IO (String, Handle)
</span><a href="System.IO.html#openTempFileWithDefaultPermissions"><span class="hs-identifier hs-var hs-var">openTempFileWithDefaultPermissions</span></a></span></span><span> </span><span id="local-6989586621679519149"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519149"><span class="hs-identifier hs-var">tmp_dir</span></a></span></span><span> </span><span id="local-6989586621679519148"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519148"><span class="hs-identifier hs-var">template</span></a></span></span><span>
</span><span id="line-507"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String -&gt; Bool -&gt; CMode -&gt; IO (String, Handle)
</span><a href="System.IO.html#openTempFile%27"><span class="hs-identifier hs-var">openTempFile'</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;openTempFileWithDefaultPermissions&quot;</span></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519149"><span class="hs-identifier hs-var">tmp_dir</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519148"><span class="hs-identifier hs-var">template</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span> </span><span class="annot"><span class="annottext">CMode
</span><span class="hs-number">0o666</span></span><span>
</span><span id="line-508"></span><span>
</span><span id="line-509"></span><span class="hs-comment">-- | Like 'openBinaryTempFile', but uses the default file permissions</span><span>
</span><span id="line-510"></span><span class="annot"><a href="System.IO.html#openBinaryTempFileWithDefaultPermissions"><span class="hs-identifier hs-type">openBinaryTempFileWithDefaultPermissions</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-511"></span><span>                                         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-512"></span><span id="openBinaryTempFileWithDefaultPermissions"><span class="annot"><span class="annottext">openBinaryTempFileWithDefaultPermissions :: String -&gt; String -&gt; IO (String, Handle)
</span><a href="System.IO.html#openBinaryTempFileWithDefaultPermissions"><span class="hs-identifier hs-var hs-var">openBinaryTempFileWithDefaultPermissions</span></a></span></span><span> </span><span id="local-6989586621679519147"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519147"><span class="hs-identifier hs-var">tmp_dir</span></a></span></span><span> </span><span id="local-6989586621679519146"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519146"><span class="hs-identifier hs-var">template</span></a></span></span><span>
</span><span id="line-513"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String -&gt; Bool -&gt; CMode -&gt; IO (String, Handle)
</span><a href="System.IO.html#openTempFile%27"><span class="hs-identifier hs-var">openTempFile'</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;openBinaryTempFileWithDefaultPermissions&quot;</span></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519147"><span class="hs-identifier hs-var">tmp_dir</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519146"><span class="hs-identifier hs-var">template</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span> </span><span class="annot"><span class="annottext">CMode
</span><span class="hs-number">0o666</span></span><span>
</span><span id="line-514"></span><span>
</span><span id="line-515"></span><span class="annot"><a href="System.IO.html#openTempFile%27"><span class="hs-identifier hs-type">openTempFile'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="System.Posix.Types.html#CMode"><span class="hs-identifier hs-type">CMode</span></a></span><span>
</span><span id="line-516"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-517"></span><span id="openTempFile%27"><span class="annot"><span class="annottext">openTempFile' :: String -&gt; String -&gt; String -&gt; Bool -&gt; CMode -&gt; IO (String, Handle)
</span><a href="System.IO.html#openTempFile%27"><span class="hs-identifier hs-var hs-var">openTempFile'</span></a></span></span><span> </span><span id="local-6989586621679519145"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519145"><span class="hs-identifier hs-var">loc</span></a></span></span><span> </span><span id="local-6989586621679519144"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519144"><span class="hs-identifier hs-var">tmp_dir</span></a></span></span><span> </span><span id="local-6989586621679519143"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519143"><span class="hs-identifier hs-var">template</span></a></span></span><span> </span><span id="local-6989586621679519142"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679519142"><span class="hs-identifier hs-var">binary</span></a></span></span><span> </span><span id="local-6989586621679519141"><span class="annot"><span class="annottext">CMode
</span><a href="#local-6989586621679519141"><span class="hs-identifier hs-var">mode</span></a></span></span><span>
</span><span id="line-518"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">String -&gt; Bool
</span><a href="System.IO.html#pathSeparator"><span class="hs-identifier hs-var">pathSeparator</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519143"><span class="hs-identifier hs-var">template</span></a></span><span>
</span><span id="line-519"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO (String, Handle)
forall a. String -&gt; IO a
</span><a href="GHC.Base.html#failIO"><span class="hs-identifier hs-var">failIO</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO (String, Handle)) -&gt; String -&gt; IO (String, Handle)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;openTempFile': Template string must not contain path separator characters: &quot;</span></span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519143"><span class="hs-identifier hs-var">template</span></a></span><span>
</span><span id="line-520"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO (String, Handle)
</span><a href="#local-6989586621679519138"><span class="hs-identifier hs-var">findTempName</span></a></span><span>
</span><span id="line-521"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-522"></span><span>    </span><span class="hs-comment">-- We split off the last extension, so we can use .foo.ext files</span><span>
</span><span id="line-523"></span><span>    </span><span class="hs-comment">-- for temporary files (hidden on Unix OSes). Unfortunately we're</span><span>
</span><span id="line-524"></span><span>    </span><span class="hs-comment">-- below filepath in the hierarchy here.</span><span>
</span><span id="line-525"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679519136"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519136"><span class="hs-identifier hs-var">prefix</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679519135"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519135"><span class="hs-identifier hs-var">suffix</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-526"></span><span>       </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">(Char -&gt; Bool) -&gt; String -&gt; (String, String)
forall a. (a -&gt; Bool) -&gt; [a] -&gt; ([a], [a])
</span><a href="GHC.List.html#break"><span class="hs-identifier hs-var">break</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'.'</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(String -&gt; (String, String)) -&gt; String -&gt; (String, String)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String
forall a. [a] -&gt; [a]
</span><a href="GHC.List.html#reverse"><span class="hs-identifier hs-var">reverse</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519143"><span class="hs-identifier hs-var">template</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-527"></span><span>         </span><span class="hs-comment">-- First case: template contains no '.'s. Just re-reverse it.</span><span>
</span><span id="line-528"></span><span>         </span><span class="hs-special">(</span><span id="local-6989586621679519132"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519132"><span class="hs-identifier hs-var">rev_suffix</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span class="hs-special">)</span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; String
forall a. [a] -&gt; [a]
</span><a href="GHC.List.html#reverse"><span class="hs-identifier hs-var">reverse</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519132"><span class="hs-identifier hs-var">rev_suffix</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-529"></span><span>         </span><span class="hs-comment">-- Second case: template contains at least one '.'. Strip the</span><span>
</span><span id="line-530"></span><span>         </span><span class="hs-comment">-- dot from the prefix and prepend it to the suffix (if we don't</span><span>
</span><span id="line-531"></span><span>         </span><span class="hs-comment">-- do this, the unique number will get added after the '.' and</span><span>
</span><span id="line-532"></span><span>         </span><span class="hs-comment">-- thus be part of the extension, which is wrong.)</span><span>
</span><span id="line-533"></span><span>         </span><span class="hs-special">(</span><span id="local-6989586621679519131"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519131"><span class="hs-identifier hs-var">rev_suffix</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'.'</span></span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span id="local-6989586621679519130"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519130"><span class="hs-identifier hs-var">rest</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; String
forall a. [a] -&gt; [a]
</span><a href="GHC.List.html#reverse"><span class="hs-identifier hs-var">reverse</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519130"><span class="hs-identifier hs-var">rest</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'.'</span></span><span class="annot"><span class="annottext">Char -&gt; String -&gt; String
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">String -&gt; String
forall a. [a] -&gt; [a]
</span><a href="GHC.List.html#reverse"><span class="hs-identifier hs-var">reverse</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519131"><span class="hs-identifier hs-var">rev_suffix</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-534"></span><span>         </span><span class="hs-comment">-- Otherwise, something is wrong, because (break (== '.')) should</span><span>
</span><span id="line-535"></span><span>         </span><span class="hs-comment">-- always return a pair with either the empty string or a string</span><span>
</span><span id="line-536"></span><span>         </span><span class="hs-comment">-- beginning with '.' as the second component.</span><span>
</span><span id="line-537"></span><span>         </span><span class="annot"><span class="annottext">(String, String)
</span><span class="hs-identifier">_</span></span><span>                      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">String -&gt; (String, String)
forall a. String -&gt; a
</span><a href="GHC.Err.html#errorWithoutStackTrace"><span class="hs-identifier hs-var">errorWithoutStackTrace</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;bug in System.IO.openTempFile&quot;</span></span><span class="hs-cpp">
#if defined(mingw32_HOST_OS)
</span><span>    </span><span id="local-6989586621679519138"><span class="annot"><span class="annottext">findTempName :: IO (String, Handle)
</span><a href="#local-6989586621679519138"><span class="hs-identifier hs-var hs-var">findTempName</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO (String, Handle)
</span><a href="#local-6989586621679519128"><span class="hs-identifier hs-var">findTempNamePosix</span></a></span><span> </span><span class="annot"><span class="annottext">IO (String, Handle) -&gt; IO (String, Handle) -&gt; IO (String, Handle)
forall a. a -&gt; a -&gt; a
</span><a href="GHC.IO.SubSystem.html#%3C%21%3E"><span class="hs-operator hs-var">&lt;!&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">IO (String, Handle)
</span><a href="#local-6989586621679519126"><span class="hs-identifier hs-var">findTempNameWinIO</span></a></span><span>
</span><span id="line-540"></span><span>
</span><span id="line-541"></span><span>    </span><span id="local-6989586621679519126"><span class="annot"><span class="annottext">findTempNameWinIO :: IO (String, Handle)
</span><a href="#local-6989586621679519126"><span class="hs-identifier hs-var hs-var">findTempNameWinIO</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-542"></span><span>      </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679519109"><span class="annot"><span class="annottext">label :: String
</span><a href="#local-6989586621679519109"><span class="hs-keyword hs-var hs-var">label</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">String -&gt; Bool
forall a. [a] -&gt; Bool
</span><a href="GHC.List.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519136"><span class="hs-identifier hs-var">prefix</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ghc&quot;</span></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519136"><span class="hs-identifier hs-var">prefix</span></a></span><span>
</span><span id="line-543"></span><span>      </span><span class="annot"><span class="annottext">String
-&gt; (Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle)
forall a. String -&gt; (Ptr CWchar -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCWString"><span class="hs-identifier hs-var">withCWString</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519144"><span class="hs-identifier hs-var">tmp_dir</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle))
-&gt; (Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679519106"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519106"><span class="hs-identifier hs-var">c_tmp_dir</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-544"></span><span>        </span><span class="annot"><span class="annottext">String
-&gt; (Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle)
forall a. String -&gt; (Ptr CWchar -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCWString"><span class="hs-identifier hs-var">withCWString</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519109"><span class="hs-keyword hs-var">label</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle))
-&gt; (Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679519105"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519105"><span class="hs-identifier hs-var">c_template</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-545"></span><span>          </span><span class="annot"><span class="annottext">String
-&gt; (Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle)
forall a. String -&gt; (Ptr CWchar -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCWString"><span class="hs-identifier hs-var">withCWString</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519135"><span class="hs-identifier hs-var">suffix</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle))
-&gt; (Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679519104"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519104"><span class="hs-identifier hs-var">c_suffix</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-546"></span><span>            </span><span id="local-6989586621679519103"><span class="annot"><span class="annottext">Ptr (Ptr CWchar)
</span><a href="#local-6989586621679519103"><span class="hs-identifier hs-var">c_ptr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; IO (Ptr (Ptr CWchar))
forall a. Storable a =&gt; a -&gt; IO (Ptr a)
</span><a href="Foreign.Marshal.Utils.html#new"><span class="hs-identifier hs-var">new</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
forall a. Ptr a
</span><a href="GHC.Ptr.html#nullPtr"><span class="hs-identifier hs-var">nullPtr</span></a></span><span>
</span><span id="line-547"></span><span>            </span><span id="local-6989586621679519101"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679519101"><span class="hs-identifier hs-var">res</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
-&gt; Ptr CWchar -&gt; Ptr CWchar -&gt; Ptr (Ptr CWchar) -&gt; IO Bool
</span><a href="System.IO.html#c_createUUIDTempFileErrNo"><span class="hs-identifier hs-var">c_createUUIDTempFileErrNo</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519106"><span class="hs-identifier hs-var">c_tmp_dir</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519105"><span class="hs-identifier hs-var">c_template</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519104"><span class="hs-identifier hs-var">c_suffix</span></a></span><span>
</span><span id="line-548"></span><span>                                             </span><span class="annot"><span class="annottext">Ptr (Ptr CWchar)
</span><a href="#local-6989586621679519103"><span class="hs-identifier hs-var">c_ptr</span></a></span><span>
</span><span id="line-549"></span><span>            </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679519101"><span class="hs-identifier hs-var">res</span></a></span><span>
</span><span id="line-550"></span><span>               </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679519098"><span class="annot"><span class="annottext">Errno
</span><a href="#local-6989586621679519098"><span class="hs-identifier hs-var">errno</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO Errno
</span><a href="Foreign.C.Error.html#getErrno"><span class="hs-identifier hs-var">getErrno</span></a></span><span>
</span><span id="line-551"></span><span>                       </span><span class="annot"><span class="annottext">IOError -&gt; IO (String, Handle)
forall a. IOError -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioError"><span class="hs-identifier hs-var">ioError</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; Errno -&gt; Maybe Handle -&gt; Maybe String -&gt; IOError
</span><a href="Foreign.C.Error.html#errnoToIOError"><span class="hs-identifier hs-var">errnoToIOError</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519145"><span class="hs-identifier hs-var">loc</span></a></span><span> </span><span class="annot"><span class="annottext">Errno
</span><a href="#local-6989586621679519098"><span class="hs-identifier hs-var">errno</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; Maybe String
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519144"><span class="hs-identifier hs-var">tmp_dir</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-552"></span><span>               </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679519095"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519095"><span class="hs-identifier hs-var">c_p</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr (Ptr CWchar) -&gt; IO (Ptr CWchar)
forall a. Storable a =&gt; Ptr a -&gt; IO a
</span><a href="Foreign.Storable.html#peek"><span class="hs-identifier hs-var">peek</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr (Ptr CWchar)
</span><a href="#local-6989586621679519103"><span class="hs-identifier hs-var">c_ptr</span></a></span><span>
</span><span id="line-553"></span><span>                       </span><span id="local-6989586621679519093"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519093"><span class="hs-identifier hs-var">filename</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; IO String
</span><a href="Foreign.C.String.html#peekCWString"><span class="hs-identifier hs-var">peekCWString</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519095"><span class="hs-identifier hs-var">c_p</span></a></span><span>
</span><span id="line-554"></span><span>                       </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; IO ()
forall a. Ptr a -&gt; IO ()
</span><a href="Foreign.Marshal.Alloc.html#free"><span class="hs-identifier hs-var">free</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519095"><span class="hs-identifier hs-var">c_p</span></a></span><span>
</span><span id="line-555"></span><span>                       </span><span class="annot"><span class="annottext">String -&gt; Bool -&gt; IO (String, Handle)
</span><a href="#local-6989586621679519090"><span class="hs-identifier hs-var">handleResultsWinIO</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519093"><span class="hs-identifier hs-var">filename</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">CMode -&gt; CInt
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">CMode
</span><a href="#local-6989586621679519141"><span class="hs-identifier hs-var">mode</span></a></span><span> </span><span class="annot"><span class="annottext">CInt -&gt; CInt -&gt; CInt
forall a. Bits a =&gt; a -&gt; a -&gt; a
</span><a href="Data.Bits.html#.%26."><span class="hs-operator hs-var">.&amp;.</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="System.Posix.Internals.html#o_EXCL"><span class="hs-identifier hs-var">o_EXCL</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CInt -&gt; CInt -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="System.Posix.Internals.html#o_EXCL"><span class="hs-identifier hs-var">o_EXCL</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-556"></span><span>
</span><span id="line-557"></span><span>    </span><span id="local-6989586621679519128"><span class="annot"><span class="annottext">findTempNamePosix :: IO (String, Handle)
</span><a href="#local-6989586621679519128"><span class="hs-identifier hs-var hs-var">findTempNamePosix</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-558"></span><span>      </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679519075"><span class="annot"><span class="annottext">label :: String
</span><a href="#local-6989586621679519075"><span class="hs-keyword hs-var hs-var">label</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">String -&gt; Bool
forall a. [a] -&gt; Bool
</span><a href="GHC.List.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519136"><span class="hs-identifier hs-var">prefix</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ghc&quot;</span></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519136"><span class="hs-identifier hs-var">prefix</span></a></span><span>
</span><span id="line-559"></span><span>      </span><span class="annot"><span class="annottext">String
-&gt; (Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle)
forall a. String -&gt; (Ptr CWchar -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCWString"><span class="hs-identifier hs-var">withCWString</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519144"><span class="hs-identifier hs-var">tmp_dir</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle))
-&gt; (Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679519074"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519074"><span class="hs-identifier hs-var">c_tmp_dir</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-560"></span><span>        </span><span class="annot"><span class="annottext">String
-&gt; (Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle)
forall a. String -&gt; (Ptr CWchar -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCWString"><span class="hs-identifier hs-var">withCWString</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519075"><span class="hs-keyword hs-var">label</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle))
-&gt; (Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679519073"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519073"><span class="hs-identifier hs-var">c_template</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-561"></span><span>          </span><span class="annot"><span class="annottext">String
-&gt; (Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle)
forall a. String -&gt; (Ptr CWchar -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCWString"><span class="hs-identifier hs-var">withCWString</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519135"><span class="hs-identifier hs-var">suffix</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle))
-&gt; (Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679519072"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519072"><span class="hs-identifier hs-var">c_suffix</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-562"></span><span>            </span><span class="annot"><span class="annottext">Int -&gt; (Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle)
forall a b. Int -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Alloc.html#allocaBytes"><span class="hs-identifier hs-var">allocaBytes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CWchar -&gt; Int
forall a. Storable a =&gt; a -&gt; Int
</span><a href="Foreign.Storable.html#sizeOf"><span class="hs-identifier hs-var">sizeOf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CWchar
forall a. HasCallStack =&gt; a
</span><a href="GHC.Err.html#undefined"><span class="hs-identifier hs-var">undefined</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CWchar"><span class="hs-identifier hs-type">CWchar</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">260</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">((Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle))
-&gt; (Ptr CWchar -&gt; IO (String, Handle)) -&gt; IO (String, Handle)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679519067"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519067"><span class="hs-identifier hs-var">c_str</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-563"></span><span>            </span><span id="local-6989586621679519066"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679519066"><span class="hs-identifier hs-var">res</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
-&gt; Ptr CWchar -&gt; Ptr CWchar -&gt; CUInt -&gt; Ptr CWchar -&gt; IO Bool
</span><a href="System.IO.html#c_getTempFileNameErrorNo"><span class="hs-identifier hs-var">c_getTempFileNameErrorNo</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519074"><span class="hs-identifier hs-var">c_tmp_dir</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519073"><span class="hs-identifier hs-var">c_template</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519072"><span class="hs-identifier hs-var">c_suffix</span></a></span><span> </span><span class="annot"><span class="annottext">CUInt
</span><span class="hs-number">0</span></span><span>
</span><span id="line-564"></span><span>                                            </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519067"><span class="hs-identifier hs-var">c_str</span></a></span><span>
</span><span id="line-565"></span><span>            </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679519066"><span class="hs-identifier hs-var">res</span></a></span><span>
</span><span id="line-566"></span><span>               </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679519064"><span class="annot"><span class="annottext">Errno
</span><a href="#local-6989586621679519064"><span class="hs-identifier hs-var">errno</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO Errno
</span><a href="Foreign.C.Error.html#getErrno"><span class="hs-identifier hs-var">getErrno</span></a></span><span>
</span><span id="line-567"></span><span>                       </span><span class="annot"><span class="annottext">IOError -&gt; IO (String, Handle)
forall a. IOError -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioError"><span class="hs-identifier hs-var">ioError</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; Errno -&gt; Maybe Handle -&gt; Maybe String -&gt; IOError
</span><a href="Foreign.C.Error.html#errnoToIOError"><span class="hs-identifier hs-var">errnoToIOError</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519145"><span class="hs-identifier hs-var">loc</span></a></span><span> </span><span class="annot"><span class="annottext">Errno
</span><a href="#local-6989586621679519064"><span class="hs-identifier hs-var">errno</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; Maybe String
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519144"><span class="hs-identifier hs-var">tmp_dir</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-568"></span><span>               </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679519063"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519063"><span class="hs-identifier hs-var">filename</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; IO String
</span><a href="Foreign.C.String.html#peekCWString"><span class="hs-identifier hs-var">peekCWString</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519067"><span class="hs-identifier hs-var">c_str</span></a></span><span>
</span><span id="line-569"></span><span>                       </span><span class="annot"><span class="annottext">String -&gt; IO (String, Handle)
</span><a href="#local-6989586621679519062"><span class="hs-identifier hs-var">handleResultsPosix</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519063"><span class="hs-identifier hs-var">filename</span></a></span><span>
</span><span id="line-570"></span><span>
</span><span id="line-571"></span><span>    </span><span id="local-6989586621679519062"><span class="annot"><span class="annottext">handleResultsPosix :: String -&gt; IO (String, Handle)
</span><a href="#local-6989586621679519062"><span class="hs-identifier hs-var hs-var">handleResultsPosix</span></a></span></span><span> </span><span id="local-6989586621679519052"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519052"><span class="hs-identifier hs-var">filename</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-572"></span><span>      </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679519050"><span class="annot"><span class="annottext">oflags1 :: CInt
</span><a href="#local-6989586621679519050"><span class="hs-identifier hs-var hs-var">oflags1</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="System.IO.html#rw_flags"><span class="hs-identifier hs-var">rw_flags</span></a></span><span> </span><span class="annot"><span class="annottext">CInt -&gt; CInt -&gt; CInt
forall a. Bits a =&gt; a -&gt; a -&gt; a
</span><a href="Data.Bits.html#.%7C."><span class="hs-operator hs-var">.|.</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="System.Posix.Internals.html#o_EXCL"><span class="hs-identifier hs-var">o_EXCL</span></a></span><span>
</span><span id="line-573"></span><span>          </span><span id="local-6989586621679519046"><span class="annot"><span class="annottext">binary_flags :: CInt
</span><a href="#local-6989586621679519046"><span class="hs-identifier hs-var hs-var">binary_flags</span></a></span></span><span>
</span><span id="line-574"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679519142"><span class="hs-identifier hs-var">binary</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="System.Posix.Internals.html#o_BINARY"><span class="hs-identifier hs-var">o_BINARY</span></a></span><span>
</span><span id="line-575"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CInt
</span><span class="hs-number">0</span></span><span>
</span><span id="line-576"></span><span>          </span><span id="local-6989586621679519043"><span class="annot"><span class="annottext">oflags :: CInt
</span><a href="#local-6989586621679519043"><span class="hs-identifier hs-var hs-var">oflags</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679519050"><span class="hs-identifier hs-var">oflags1</span></a></span><span> </span><span class="annot"><span class="annottext">CInt -&gt; CInt -&gt; CInt
forall a. Bits a =&gt; a -&gt; a -&gt; a
</span><a href="Data.Bits.html#.%7C."><span class="hs-operator hs-var">.|.</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679519046"><span class="hs-identifier hs-var">binary_flags</span></a></span><span>
</span><span id="line-577"></span><span>      </span><span id="local-6989586621679519042"><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679519042"><span class="hs-identifier hs-var">fd</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">String -&gt; (Ptr CWchar -&gt; IO CInt) -&gt; IO CInt
forall a. String -&gt; (Ptr CWchar -&gt; IO a) -&gt; IO a
</span><a href="System.Posix.Internals.html#withFilePath"><span class="hs-identifier hs-var">withFilePath</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519052"><span class="hs-identifier hs-var">filename</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr CWchar -&gt; IO CInt) -&gt; IO CInt)
-&gt; (Ptr CWchar -&gt; IO CInt) -&gt; IO CInt
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679519040"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519040"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; CInt -&gt; CMode -&gt; IO CInt
</span><a href="System.Posix.Internals.html#c_open"><span class="hs-identifier hs-var">c_open</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679519040"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679519043"><span class="hs-identifier hs-var">oflags</span></a></span><span> </span><span class="annot"><span class="annottext">CMode
</span><a href="#local-6989586621679519141"><span class="hs-identifier hs-var">mode</span></a></span><span>
</span><span id="line-578"></span><span>      </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679519042"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">CInt -&gt; CInt -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><span class="hs-number">0</span></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-579"></span><span>        </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679519037"><span class="annot"><span class="annottext">Errno
</span><a href="#local-6989586621679519037"><span class="hs-identifier hs-var">errno</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO Errno
</span><a href="Foreign.C.Error.html#getErrno"><span class="hs-identifier hs-var">getErrno</span></a></span><span>
</span><span id="line-580"></span><span>                   </span><span class="annot"><span class="annottext">IOError -&gt; IO (String, Handle)
forall a. IOError -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioError"><span class="hs-identifier hs-var">ioError</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; Errno -&gt; Maybe Handle -&gt; Maybe String -&gt; IOError
</span><a href="Foreign.C.Error.html#errnoToIOError"><span class="hs-identifier hs-var">errnoToIOError</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519145"><span class="hs-identifier hs-var">loc</span></a></span><span> </span><span class="annot"><span class="annottext">Errno
</span><a href="#local-6989586621679519037"><span class="hs-identifier hs-var">errno</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; Maybe String
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519144"><span class="hs-identifier hs-var">tmp_dir</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-581"></span><span>        </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-582"></span><span>          </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679519036"><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679519036"><span class="hs-identifier hs-var">fD</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679519035"><span class="annot"><span class="annottext">IODeviceType
</span><a href="#local-6989586621679519035"><span class="hs-identifier hs-var">fd_type</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CInt
-&gt; IOMode
-&gt; Maybe (IODeviceType, CDev, CIno)
-&gt; Bool
-&gt; Bool
-&gt; IO (FD, IODeviceType)
</span><a href="GHC.IO.FD.html#mkFD"><span class="hs-identifier hs-var">FD.mkFD</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679519042"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="GHC.IO.IOMode.html#ReadWriteMode"><span class="hs-identifier hs-var">ReadWriteMode</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (IODeviceType, CDev, CIno)
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-comment">{-no stat-}</span><span>
</span><span id="line-583"></span><span>                                     </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-comment">{-is_socket-}</span><span>
</span><span id="line-584"></span><span>                                     </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span class="hs-comment">{-is_nonblock-}</span><span>
</span><span id="line-585"></span><span>
</span><span id="line-586"></span><span>             </span><span id="local-6989586621679519033"><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679519033"><span class="hs-identifier hs-var">enc</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO TextEncoding
</span><a href="GHC.IO.Encoding.html#getLocaleEncoding"><span class="hs-identifier hs-var">getLocaleEncoding</span></a></span><span>
</span><span id="line-587"></span><span>             </span><span id="local-6989586621679519031"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679519031"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FD
-&gt; IODeviceType
-&gt; String
-&gt; IOMode
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; IO Handle
</span><a href="GHC.IO.Handle.FD.html#mkHandleFromFD"><span class="hs-identifier hs-var">POSIX.mkHandleFromFD</span></a></span><span> </span><span class="annot"><span class="annottext">FD
</span><a href="#local-6989586621679519036"><span class="hs-identifier hs-var">fD</span></a></span><span> </span><span class="annot"><span class="annottext">IODeviceType
</span><a href="#local-6989586621679519035"><span class="hs-identifier hs-var">fd_type</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519052"><span class="hs-identifier hs-var">filename</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="GHC.IO.IOMode.html#ReadWriteMode"><span class="hs-identifier hs-var">ReadWriteMode</span></a></span><span>
</span><span id="line-588"></span><span>                                 </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-comment">{-set non-block-}</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TextEncoding -&gt; Maybe TextEncoding
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding
</span><a href="#local-6989586621679519033"><span class="hs-identifier hs-var">enc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-589"></span><span>
</span><span id="line-590"></span><span>             </span><span class="annot"><span class="annottext">(String, Handle) -&gt; IO (String, Handle)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519052"><span class="hs-identifier hs-var">filename</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679519031"><span class="hs-identifier hs-var">h</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-591"></span><span>
</span><span id="line-592"></span><span>    </span><span id="local-6989586621679519090"><span class="annot"><span class="annottext">handleResultsWinIO :: String -&gt; Bool -&gt; IO (String, Handle)
</span><a href="#local-6989586621679519090"><span class="hs-identifier hs-var hs-var">handleResultsWinIO</span></a></span></span><span> </span><span id="local-6989586621679519012"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519012"><span class="hs-identifier hs-var">filename</span></a></span></span><span> </span><span id="local-6989586621679519011"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679519011"><span class="hs-identifier hs-var">excl</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-593"></span><span>      </span><span class="hs-special">(</span><span id="local-6989586621679519010"><span class="annot"><span class="annottext">Io NativeHandle
</span><a href="#local-6989586621679519010"><span class="hs-identifier hs-var">hwnd</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679519009"><span class="annot"><span class="annottext">IODeviceType
</span><a href="#local-6989586621679519009"><span class="hs-identifier hs-var">hwnd_type</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">String -&gt; Bool -&gt; Bool -&gt; IO (Io NativeHandle, IODeviceType)
</span><a href="GHC.IO.Windows.Handle.html#openFileAsTemp"><span class="hs-identifier hs-var">openFileAsTemp</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519012"><span class="hs-identifier hs-var">filename</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679519011"><span class="hs-identifier hs-var">excl</span></a></span><span>
</span><span id="line-594"></span><span>      </span><span id="local-6989586621679519008"><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679519008"><span class="hs-identifier hs-var">mb_codec</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679519142"><span class="hs-identifier hs-var">binary</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding -&gt; IO (Maybe TextEncoding)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">(TextEncoding -&gt; Maybe TextEncoding)
-&gt; IO TextEncoding -&gt; IO (Maybe TextEncoding)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoding -&gt; Maybe TextEncoding
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">IO TextEncoding
</span><a href="GHC.IO.Encoding.html#getLocaleEncoding"><span class="hs-identifier hs-var">getLocaleEncoding</span></a></span><span>
</span><span id="line-595"></span><span>
</span><span id="line-596"></span><span>      </span><span class="hs-comment">-- then use it to make a Handle</span><span>
</span><span id="line-597"></span><span>      </span><span id="local-6989586621679519007"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679519007"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Io NativeHandle
-&gt; IODeviceType
-&gt; String
-&gt; IOMode
-&gt; Maybe TextEncoding
-&gt; IO Handle
forall dev.
(RawIO dev, IODevice dev, BufferedIO dev, Typeable dev) =&gt;
dev
-&gt; IODeviceType
-&gt; String
-&gt; IOMode
-&gt; Maybe TextEncoding
-&gt; IO Handle
</span><a href="GHC.IO.Handle.Windows.html#mkHandleFromHANDLE"><span class="hs-identifier hs-var">mkHandleFromHANDLE</span></a></span><span> </span><span class="annot"><span class="annottext">Io NativeHandle
</span><a href="#local-6989586621679519010"><span class="hs-identifier hs-var">hwnd</span></a></span><span> </span><span class="annot"><span class="annottext">IODeviceType
</span><a href="#local-6989586621679519009"><span class="hs-identifier hs-var">hwnd_type</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519012"><span class="hs-identifier hs-var">filename</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="GHC.IO.IOMode.html#ReadWriteMode"><span class="hs-identifier hs-var">ReadWriteMode</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679519008"><span class="hs-identifier hs-var">mb_codec</span></a></span><span>
</span><span id="line-598"></span><span>                </span><span class="annot"><span class="annottext">IO Handle -&gt; IO () -&gt; IO Handle
forall a b. IO a -&gt; IO b -&gt; IO a
</span><a href="Control.Exception.Base.html#onException"><span class="hs-operator hs-var">`onException`</span></a></span><span> </span><span class="annot"><span class="annottext">Io NativeHandle -&gt; IO ()
forall a. IODevice a =&gt; a -&gt; IO ()
</span><a href="GHC.IO.Device.html#close"><span class="hs-identifier hs-var">IODevice.close</span></a></span><span> </span><span class="annot"><span class="annottext">Io NativeHandle
</span><a href="#local-6989586621679519010"><span class="hs-identifier hs-var">hwnd</span></a></span><span>
</span><span id="line-599"></span><span>      </span><span class="annot"><span class="annottext">(String, Handle) -&gt; IO (String, Handle)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519012"><span class="hs-identifier hs-var">filename</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679519007"><span class="hs-identifier hs-var">h</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-600"></span><span>
</span><span id="line-601"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-string">&quot;getTempFileNameErrorNo&quot;</span></span><span> </span><span id="c_getTempFileNameErrorNo"><span class="annot"><a href="System.IO.html#c_getTempFileNameErrorNo"><span class="hs-identifier hs-var">c_getTempFileNameErrorNo</span></a></span></span><span>
</span><span id="line-602"></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.String.html#CWString"><span class="hs-identifier hs-type">CWString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.String.html#CWString"><span class="hs-identifier hs-type">CWString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.String.html#CWString"><span class="hs-identifier hs-type">CWString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CUInt"><span class="hs-identifier hs-type">CUInt</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CWchar"><span class="hs-identifier hs-type">CWchar</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>
</span><span id="line-603"></span><span>
</span><span id="line-604"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-string">&quot;__createUUIDTempFileErrNo&quot;</span></span><span> </span><span id="c_createUUIDTempFileErrNo"><span class="annot"><a href="System.IO.html#c_createUUIDTempFileErrNo"><span class="hs-identifier hs-var">c_createUUIDTempFileErrNo</span></a></span></span><span>
</span><span id="line-605"></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.String.html#CWString"><span class="hs-identifier hs-type">CWString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.String.html#CWString"><span class="hs-identifier hs-type">CWString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.String.html#CWString"><span class="hs-identifier hs-type">CWString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="Foreign.C.String.html#CWString"><span class="hs-identifier hs-type">CWString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>
</span><span id="line-606"></span><span>
</span><span id="line-607"></span><span class="annot"><a href="System.IO.html#pathSeparator"><span class="hs-identifier hs-type">pathSeparator</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>
</span><span id="line-608"></span><span id="pathSeparator"><span class="annot"><span class="annottext">pathSeparator :: String -&gt; Bool
</span><a href="System.IO.html#pathSeparator"><span class="hs-identifier hs-var hs-var">pathSeparator</span></a></span></span><span> </span><span id="local-6989586621679519003"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519003"><span class="hs-identifier hs-var">template</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Char -&gt; Bool) -&gt; String -&gt; Bool
forall a. (a -&gt; Bool) -&gt; [a] -&gt; Bool
</span><a href="GHC.List.html#any"><span class="hs-identifier hs-var">any</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679519001"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679519001"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679519001"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'/'</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%7C%7C"><span class="hs-operator hs-var">||</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679519001"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\\'</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679519003"><span class="hs-identifier hs-var">template</span></a></span><span>
</span><span id="line-609"></span><span>
</span><span id="line-610"></span><span id="output_flags"><span class="annot"><span class="annottext">output_flags :: CInt
</span><a href="System.IO.html#output_flags"><span class="hs-identifier hs-var hs-var">output_flags</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="System.IO.html#std_flags"><span class="hs-identifier hs-var">std_flags</span></a></span><span class="hs-cpp">
#else /* else mingw32_HOST_OS */
</span><span>    </span><span class="hs-identifier">findTempName</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-613"></span><span>      </span><span class="hs-identifier">rs</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">rand_string</span><span>
</span><span id="line-614"></span><span>      </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">filename</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">prefix</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-identifier">rs</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-identifier">suffix</span><span>
</span><span id="line-615"></span><span>          </span><span class="hs-identifier">filepath</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">tmp_dir</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">combine</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">filename</span><span>
</span><span id="line-616"></span><span>      </span><span class="hs-identifier">r</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">openNewFile</span><span> </span><span class="hs-identifier">filepath</span><span> </span><span class="hs-identifier">binary</span><span> </span><span class="hs-identifier">mode</span><span>
</span><span id="line-617"></span><span>      </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">r</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-618"></span><span>        </span><span class="hs-identifier">FileExists</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">findTempName</span><span>
</span><span id="line-619"></span><span>        </span><span class="hs-identifier">OpenNewError</span><span> </span><span class="hs-identifier">errno</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">ioError</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">errnoToIOError</span><span> </span><span class="hs-identifier">loc</span><span> </span><span class="hs-identifier">errno</span><span> </span><span class="hs-identifier">Nothing</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">tmp_dir</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-620"></span><span>        </span><span class="hs-identifier">NewFileCreated</span><span> </span><span class="hs-identifier">fd</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-621"></span><span>          </span><span class="hs-special">(</span><span class="hs-identifier">fD</span><span class="hs-special">,</span><span class="hs-identifier">fd_type</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">FD.mkFD</span><span> </span><span class="hs-identifier">fd</span><span> </span><span class="hs-identifier">ReadWriteMode</span><span> </span><span class="hs-identifier">Nothing</span><span class="hs-comment">{-no stat-}</span><span>
</span><span id="line-622"></span><span>                               </span><span class="hs-identifier">False</span><span class="hs-comment">{-is_socket-}</span><span>
</span><span id="line-623"></span><span>                               </span><span class="hs-identifier">True</span><span class="hs-comment">{-is_nonblock-}</span><span>
</span><span id="line-624"></span><span>
</span><span id="line-625"></span><span>          </span><span class="hs-identifier">enc</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getLocaleEncoding</span><span>
</span><span id="line-626"></span><span>          </span><span class="hs-identifier">h</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">POSIX.mkHandleFromFD</span><span> </span><span class="hs-identifier">fD</span><span> </span><span class="hs-identifier">fd_type</span><span> </span><span class="hs-identifier">filepath</span><span> </span><span class="hs-identifier">ReadWriteMode</span><span> </span><span class="hs-identifier">False</span><span class="hs-comment">{-set non-block-}</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">enc</span><span class="hs-special">)</span><span>
</span><span id="line-627"></span><span>
</span><span id="line-628"></span><span>          </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">filepath</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">h</span><span class="hs-special">)</span><span>
</span><span id="line-629"></span><span>
</span><span id="line-630"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-631"></span><span>        </span><span class="hs-comment">-- XXX bits copied from System.FilePath, since that's not available here</span><span>
</span><span id="line-632"></span><span>        </span><span class="hs-identifier">combine</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-identifier">b</span><span>
</span><span id="line-633"></span><span>                  </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">null</span><span> </span><span class="hs-identifier">b</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-634"></span><span>                  </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">null</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">b</span><span>
</span><span id="line-635"></span><span>                  </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">pathSeparator</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">last</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-identifier">b</span><span>
</span><span id="line-636"></span><span>                  </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">otherwise</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">pathSeparatorChar</span><span class="hs-special">]</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-identifier">b</span><span>
</span><span id="line-637"></span><span>
</span><span id="line-638"></span><span class="hs-identifier">tempCounter</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">IORef</span><span> </span><span class="hs-identifier">Int</span><span>
</span><span id="line-639"></span><span class="hs-identifier">tempCounter</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">unsafePerformIO</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">newIORef</span><span> </span><span class="hs-number">0</span><span>
</span><span id="line-640"></span><span class="hs-pragma">{-# NOINLINE</span><span> </span><span class="hs-pragma">tempCounter</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-641"></span><span>
</span><span id="line-642"></span><span class="hs-comment">-- build large digit-alike number</span><span>
</span><span id="line-643"></span><span class="hs-identifier">rand_string</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">String</span><span>
</span><span id="line-644"></span><span class="hs-identifier">rand_string</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-645"></span><span>  </span><span class="hs-identifier">r1</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">c_getpid</span><span>
</span><span id="line-646"></span><span>  </span><span class="hs-special">(</span><span class="hs-identifier">r2</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">_</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">atomicModifyIORef'_</span><span> </span><span class="hs-identifier">tempCounter</span><span> </span><span class="hs-special">(</span><span class="hs-operator">+</span><span class="hs-number">1</span><span class="hs-special">)</span><span>
</span><span id="line-647"></span><span>  </span><span class="hs-identifier">return</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">show</span><span> </span><span class="hs-identifier">r1</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-string">&quot;-&quot;</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-identifier">show</span><span> </span><span class="hs-identifier">r2</span><span>
</span><span id="line-648"></span><span>
</span><span id="line-649"></span><span class="hs-keyword">data</span><span> </span><span class="hs-identifier">OpenNewFileResult</span><span>
</span><span id="line-650"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">NewFileCreated</span><span> </span><span class="hs-identifier">CInt</span><span>
</span><span id="line-651"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">FileExists</span><span>
</span><span id="line-652"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">OpenNewError</span><span> </span><span class="hs-identifier">Errno</span><span>
</span><span id="line-653"></span><span>
</span><span id="line-654"></span><span class="hs-identifier">openNewFile</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">FilePath</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Bool</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CMode</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">OpenNewFileResult</span><span>
</span><span id="line-655"></span><span class="hs-identifier">openNewFile</span><span> </span><span class="hs-identifier">filepath</span><span> </span><span class="hs-identifier">binary</span><span> </span><span class="hs-identifier">mode</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-656"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">oflags1</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">rw_flags</span><span> </span><span class="hs-operator">.|.</span><span> </span><span class="hs-identifier">o_EXCL</span><span>
</span><span id="line-657"></span><span>
</span><span id="line-658"></span><span>      </span><span class="hs-identifier">binary_flags</span><span>
</span><span id="line-659"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">binary</span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">o_BINARY</span><span>
</span><span id="line-660"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">otherwise</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-number">0</span><span>
</span><span id="line-661"></span><span>
</span><span id="line-662"></span><span>      </span><span class="hs-identifier">oflags</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">oflags1</span><span> </span><span class="hs-operator">.|.</span><span> </span><span class="hs-identifier">binary_flags</span><span>
</span><span id="line-663"></span><span>  </span><span class="hs-identifier">fd</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">withFilePath</span><span> </span><span class="hs-identifier">filepath</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span> </span><span class="hs-identifier">f</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-664"></span><span>          </span><span class="hs-identifier">c_open</span><span> </span><span class="hs-identifier">f</span><span> </span><span class="hs-identifier">oflags</span><span> </span><span class="hs-identifier">mode</span><span>
</span><span id="line-665"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">fd</span><span> </span><span class="hs-operator">&lt;</span><span> </span><span class="hs-number">0</span><span>
</span><span id="line-666"></span><span>    </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-667"></span><span>      </span><span class="hs-identifier">errno</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getErrno</span><span>
</span><span id="line-668"></span><span>      </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">errno</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-669"></span><span>        </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">errno</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-identifier">eEXIST</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">FileExists</span><span>
</span><span id="line-670"></span><span>        </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">OpenNewError</span><span> </span><span class="hs-identifier">errno</span><span class="hs-special">)</span><span>
</span><span id="line-671"></span><span>    </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">NewFileCreated</span><span> </span><span class="hs-identifier">fd</span><span class="hs-special">)</span><span>
</span><span id="line-672"></span><span>
</span><span id="line-673"></span><span class="hs-comment">-- XXX Should use filepath library</span><span>
</span><span id="line-674"></span><span class="hs-identifier">pathSeparatorChar</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Char</span><span>
</span><span id="line-675"></span><span class="hs-identifier">pathSeparatorChar</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-char">'/'</span><span>
</span><span id="line-676"></span><span>
</span><span id="line-677"></span><span class="hs-identifier">pathSeparator</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-678"></span><span class="hs-identifier">pathSeparator</span><span> </span><span class="hs-identifier">template</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">pathSeparatorChar</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">elem</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">template</span><span>
</span><span id="line-679"></span><span>
</span><span id="line-680"></span><span class="hs-identifier">output_flags</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">std_flags</span><span>    </span><span class="hs-operator">.|.</span><span> </span><span class="hs-identifier">o_CREAT</span><span class="hs-cpp">
#endif /* mingw32_HOST_OS */
</span><span>
</span><span id="line-683"></span><span class="hs-comment">-- XXX Copied from GHC.Handle</span><span>
</span><span id="line-684"></span><span class="annot"><a href="System.IO.html#std_flags"><span class="hs-identifier hs-type">std_flags</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="System.IO.html#output_flags"><span class="hs-identifier hs-type">output_flags</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="System.IO.html#rw_flags"><span class="hs-identifier hs-type">rw_flags</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span>
</span><span id="line-685"></span><span id="std_flags"><span class="annot"><span class="annottext">std_flags :: CInt
</span><a href="System.IO.html#std_flags"><span class="hs-identifier hs-var hs-var">std_flags</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="System.Posix.Internals.html#o_NONBLOCK"><span class="hs-identifier hs-var">o_NONBLOCK</span></a></span><span>   </span><span class="annot"><span class="annottext">CInt -&gt; CInt -&gt; CInt
forall a. Bits a =&gt; a -&gt; a -&gt; a
</span><a href="Data.Bits.html#.%7C."><span class="hs-operator hs-var">.|.</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="System.Posix.Internals.html#o_NOCTTY"><span class="hs-identifier hs-var">o_NOCTTY</span></a></span><span>
</span><span id="line-686"></span><span id="rw_flags"><span class="annot"><span class="annottext">rw_flags :: CInt
</span><a href="System.IO.html#rw_flags"><span class="hs-identifier hs-var hs-var">rw_flags</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="System.IO.html#output_flags"><span class="hs-identifier hs-var">output_flags</span></a></span><span> </span><span class="annot"><span class="annottext">CInt -&gt; CInt -&gt; CInt
forall a. Bits a =&gt; a -&gt; a -&gt; a
</span><a href="Data.Bits.html#.%7C."><span class="hs-operator hs-var">.|.</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="System.Posix.Internals.html#o_RDWR"><span class="hs-identifier hs-var">o_RDWR</span></a></span><span>
</span><span id="line-687"></span><span>
</span><span id="line-688"></span><span class="hs-comment">-- $locking</span><span>
</span><span id="line-689"></span><span class="hs-comment">-- Implementations should enforce as far as possible, at least locally to the</span><span>
</span><span id="line-690"></span><span class="hs-comment">-- Haskell process, multiple-reader single-writer locking on files.</span><span>
</span><span id="line-691"></span><span class="hs-comment">-- That is, /there may either be many handles on the same file which manage input, or just one handle on the file which manages output/.  If any</span><span>
</span><span id="line-692"></span><span class="hs-comment">-- open or semi-closed handle is managing a file for output, no new</span><span>
</span><span id="line-693"></span><span class="hs-comment">-- handle can be allocated for that file.  If any open or semi-closed</span><span>
</span><span id="line-694"></span><span class="hs-comment">-- handle is managing a file for input, new handles can only be allocated</span><span>
</span><span id="line-695"></span><span class="hs-comment">-- if they do not manage output.  Whether two files are the same is</span><span>
</span><span id="line-696"></span><span class="hs-comment">-- implementation-dependent, but they should normally be the same if they</span><span>
</span><span id="line-697"></span><span class="hs-comment">-- have the same absolute path name and neither has been renamed, for</span><span>
</span><span id="line-698"></span><span class="hs-comment">-- example.</span><span>
</span><span id="line-699"></span><span class="hs-comment">--</span><span>
</span><span id="line-700"></span><span class="hs-comment">-- /Warning/: the 'readFile' operation holds a semi-closed handle on</span><span>
</span><span id="line-701"></span><span class="hs-comment">-- the file until the entire contents of the file have been consumed.</span><span>
</span><span id="line-702"></span><span class="hs-comment">-- It follows that an attempt to write to a file (using 'writeFile', for</span><span>
</span><span id="line-703"></span><span class="hs-comment">-- example) that was earlier opened by 'readFile' will usually result in</span><span>
</span><span id="line-704"></span><span class="hs-comment">-- failure with 'System.IO.Error.isAlreadyInUseError'.</span><span>
</span><span id="line-705"></span></pre></body></html>